輸入一串字元,直到輸入星號為止,輸出其中英文字母個數和數字字元個數

2021-04-20 13:03:19 字數 6258 閱讀 3771

1樓:非常可愛

錯誤**:

if('a'<=nextchar<='z'||'a'<=nextchar<='z')

else if('0'<=nextchar<='9')修改後:

#include

int main()

}擴充套件資料

c++輸入一行字元,分別統計出其中英文字母、空格、數字和其他字元的個數。

#include

int main()

printf("%d %d %d %d\n",a,b,c,d);

return 0;}

2樓:匿名使用者

錯誤**:

1.'a'<=nextchar<='z'||'a'<=nextchar<='z';

2.'0'<=nextchar<='9'。

錯誤原因:當多個條件時,需要使用邏輯運算子。

修改後**為:

int main(void)

else if (c == ' ')

else if (c >= '0'&&c <= '9')else

}printf("字母=%d,數字=%d,空格=%d,其他

return 0;}

3樓:匿名使用者

一、問題分析:

輸入一行字母,那麼會以換行結束。所以可以存入陣列,也可以逐個輸入,遇到換行結束。

要統計各個類的個數,就要逐個判斷是哪個分類的。

由於在ascii碼中,數字,大寫字母,小寫字母分別連續,所以可以根據邊界值判斷型別。

二、演算法設計:

1、讀入字元,直到遇到換行結束。

2、對於每個字元,判斷是字母還是數字,或者空格,或者是其它字元。

3、對於每個字元判斷後,對應類別計數器自加。

4、最終輸出結果。

三、參考**:

#include

int main()

printf("%d %d %d %d\n", a,b,c,d);//輸出結果。

return 0;}

4樓:gta小雞

開始↓gets()讀一行字元存到char *s中strlen()函式求字串s長度

陣列cal[4]用來累計字母、空格、數字、特殊字元的個數for(i=0;i

輸出cal陣列各元素的值結束

5樓:匿名使用者

即學了程式設計又學了英語(沒學好……),豈不美哉?

(printf()函式能用那種方式是因版本的關係)

本程式的優點:不受到字串長度的限制,執行效率高

#include

int main (void)

++resnum;                    //attention! because of the newline (ascii: 10)!

//data output

printf ("\nthe results of data processing are as fellows.\n");

printf ("the number of letters:%8d\n"

"the number of space: %8d\n"

"the number of digits: %8d\n"

"the number of others:%8d\n",

letnum, spanum, dignum, resnum);

//the end

printf ("\nthank you for your using!");

return 0;}

6樓:匿名使用者

#include

int main()

if(e>='0' && e<='9')// 數字是'0'到'9'的字元,不是ascii值0到9

if((e>=65&&e<=90)||(e>=97&&e<=122))//用c來接受字母的個數

else //用d來接受其他字元的個數

}printf("共輸入空格%d個\n",a);

printf("共輸入數字%d個\n",b);

printf("共輸入字母%d個\n",c);

printf("共輸入其他字元%d個\n",d);

return 0;}

7樓:匿名使用者

clear

accept "請輸入一串字元:" to xstore 0 to dyw,xyw,kg,sz,qtm=len(x)

for i=1 to m

x1=substr(x,i,1)

k=asc(x1)

do case

case k=32

kg=kg+1

case k>=48 and k<=57

sz=sz+1

case k>=65 and k<=90

dyw=dyw+1

case k>=97 and k<=122xyw=xyw+1

other

qt=qt+1

endcase

endfor

?"其中空格有: "+alltrim(str(kg))+"個"

?"大寫字母有: "+alltrim(str(dyw))+"個"

?"小寫字母有: "+alltrim(str(xyw))+"個"

?"數字有: "+alltrim(str(sz))+"個"

?"其它字元有: "+alltrim(str(qt))+"個"

8樓:匿名使用者

#include

int main(void)

else if(ch==' ')

else if(ch>='0'&&ch<='9')else

}printf("字母= %d,空格= %d,數字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num);

return 0;}

9樓:程式設計師的每一天

c語言經典例子之統計英文、字母、空格及數字個數

10樓:瞌睡貓然

1 while語句:

#include

int main(void)

else if(ch==' ')

else if(ch>='0'&&ch<='9')else

}printf("字母= %d,空格= %d,數字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num);

return 0;

}2 ,do while語句:

#include

int main(void)

else if(ch==' ')

else if(ch>='0'&&ch<='9')else

} while((ch=getchar())!='\n')//回車鍵結束輸入,並且回車符不計入

printf("字母= %d,空格= %d,數字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num);

return 0;}

11樓:聽不清啊

#include

int main()

12樓:我的小名叫仙女

|#include

#define n 100

int main()

printf("英文字母:%d\n",m);

printf("數字字元:%d\n",n);

printf("空格:%d\n",b);

printf("其他字元:%d\n",c);

return 0;}

13樓:

#include

#include

int main()

int qt=strlen(c)-zm-sz-kg;

printf("字母為%d 空格為%d 數字為%d 其它為%d\n",zm,kg,sz,qt);

return 0;

}望採納,不懂可追問.

14樓:匿名使用者

輸入一行字元=input("請輸入任意資料:")

數字個數=len(list(i for i in 輸入一行字元 if i.isdigit()==1))

中英文字母個數=len(list((i for i in 輸入一行字元 if i.isalpha()==1)))

空格個數=len(list(i for i in 輸入一行字元 if i==" "))

其他個數=len(輸入一行字元)-數字個數-中英文字母個數-空格個數

print("中有個數字,箇中英文字母,個空格個數,個其他".format(輸入一行字元,數字個數,中英文字母個數,空格個數,其他個數))

15樓:匿名使用者

#include

#include

#define a 80

main()

printf("英文字元有:

%d\n",letter);

printf("數字字元有:%d\n",digit);

printf("空格有:%d\n",space);

printf("其他字元有:%d\n",others);}

16樓:匿名使用者

非要限制輸入的大小麼?過會兒給你發個

#include

#include

void main()

printf("lowercase:%d\t uppercase:%d\t digit:

%d\t space:%d\t others:%d\n",lowercase,uppercase,digit,space,others);}

17樓:磨砂玻璃杯

第10行改為if('a'<=nextchar&&nextchar<='z'||'a'<=nextchar&&nextchar<='z')

14行改為else if('0'<=nextchar&&nextchar<='9')

不能用你那種形式來表示集合

18樓:匿名使用者

只要做一個迴圈,求每一個字元的ascii碼,然後進行比較便可以得出其的總數

char *str1="abcde 123456 6/\{}"

int a[4]=;

char temp_data;

unsigned char temp_data;

int i;

for(i=0;i=0x30 &&temp_data<=39) a[0]++;

else

if((temp_data>=0x41 &&temp_data<=5a)||(temp_data>=0x61 &&temp_data<=7a)) a[1]++;

else

if(temp_data==0x20) a[2]++;

else a[3]==;

}for(i=0;i<4;i++)

19樓:陌c離

#include

#include

int main()

輸入一行字元,分別統計出其中英文字母,空格,數字和其他字元的個數

20樓:凌亂心扉

#include

int main()

printf("字母有%d個,數字有%d個,空格有%d個,其他有%d個",letters,digits,spaces,others);

return 0;

}while語句若一直滿足條件,則會不斷的重複下去。但有時,需要停止迴圈,則可以用下面的三種方式:

一、在while語句中設定條件語句,條件不滿足,則迴圈自動停止。

如:只輸出3的倍數的迴圈;可以設定範圍為:0到20。

二、在迴圈結構中加入流程控制語句,可以使使用者退出迴圈。

1、break流程控制:強制中斷該執行區內的語句,跳出該執行區,繼續執行區域外的語句。

2、continue流程控制:也是中斷迴圈內的執行操作,並且從頭開始執行。

三、利用標識來控制while語句的結束時間。

C 程式設計中,輸入一串字元,將輸入的小寫改成大寫,其餘不變輸出

cstring str abc123 str.makeupper 改變字元的大寫 str abc123 別偷懶,自己敲,把書本後的ascii值表看看就知道了,都這麼走過來的 include stdafx.h if the vc 6.0,with this line.include include u...

輸入一批非0數,直到輸入0時為止,計算其中奇數的平均值和偶數中的最大值和最小值

j沒初值 設定為0 同學你是女的吧,我親自來指導你 輸入一批非0數,直到輸入0為止,計算其中奇數的平均值和偶數的乘積,我剛學c語言,有沒有大神幫忙看看 10 通過迴圈輸入計算奇數的和以及個數並求平均值,計算偶數的乘積,迴圈的時候並判斷奇偶性 13.輸入一批非0數,直到輸入0時為止,計算其中奇數的平均...

編寫一下程式從鍵盤上輸入字串,統計字串中英文字母的個數及數字的個數

不用那麼複雜,漢字倆位元組,英文一個位元組,計算下關係就可以了 public class test public class test else if value 65 value 90 value 97 value 122 else system.out.println 數字個數 num 字母個數...