題目 求出給定字串中大寫字母 小寫字母 數字 空格及其他字元的個數。注意C 題目

2021-07-08 21:14:06 字數 6306 閱讀 7448

1樓:

#include

int letter,digit,space,others;

int main()

void count(char str)

2樓:自戀狂

#include

#include

#include

using namespace std;

#include

int main()

else if(c[str.length()-l-1]>='a'&&c[str.length()-l-1]<='z')

else if(c[str.length()-l-1]>='0'&&c[str.length()-l-1]<='9')

else if(c[str.length()-l-1]==' ')else qita++;

}cout<<"大寫:"<

"<

free(c);

return 0;}

c++輸入一行字串,要求分別統計出其中英文大寫字母、小寫字母、數字、空格以及其他字元的個數。誰會啊?

3樓:薛遠乾煙

#include

"stdio.h"

#include

"string.h"

void

main()

printf("有字母%d個,數字%d個,空格%d個,其他字元%d個。",letter,num,space,other);}

4樓:匿名使用者

你必須包含ctype.h

然後使用isupper,islower,isdigit,isspace分別判斷大寫,小寫,數字,和空格,當然如果你熟悉ascii表,可以直接根據值的大小來判斷字元的屬性.

5樓:

#include

#include

int main()

printf("%d digit(s), %d upper case(s), %d lower case(s), %d space(s), %d other(s)\n", digit, upper, lower);}

給定程式的功能是分別統計字串中大寫字母和小寫字母的個數

6樓:

c++語言:

#include

#include

using namespace std;

int main()

cout<<"其中的小寫字母個數是:"

}擴充套件資料:1、while迴圈:

只要給定的條件為真,while 迴圈語句會重複執行一個目標語句。

語法:while(condition)

在這裡,statement(s) 可以是一個單獨的語句,也可以是幾個語句組成的**塊。condition 可以是任意的表示式,當為任意非零值時都為真。當條件為真時執行迴圈。

當條件為假時,程式流將繼續執行緊接著迴圈的下一條語句。

2、if語句:

一個 if 語句 後可跟一個可選的 else 語句,else 語句在布林表示式為假時執行。

語法:if(boolean_expression)else

如果布林表示式為 true,則執行 if 塊內的**。如果布林表示式為 false,則執行 else 塊內的**。

7樓:匿名使用者

用c語言幫你寫了個. 通過函式實現這個功能. 如果有問題還請追問. 望採納!#include //函式實現統計字串中大寫字母和小寫字母的個數.

void count(char *a,int *capital,int *lowercase)

}int main()

截圖如下:

8樓:匿名使用者

兩個計數器 遍歷字串 遍歷的時候把字元轉成int 如果大於91 就是大寫 否則就是小寫 兩個計數器分別統計遍歷完了列印就行了

9樓:匿名使用者

int daxie = 0;

int xiaoxie = 0;

string value = "";

foreach (char var in value)else if (var >= 'a' && var <= 'z')}

c程式設計:輸入一行文字,分別統計出其中的英文大寫字母、小寫字母、單詞、數字、空格以及其他字元的個

10樓:匿名使用者

#include

#include

void fun(char *p);

int main()

void fun(char *p)

printf("大寫字母:

答%d\n小寫字母:%d\n空格:%d\n數字:%d\n其他字元:%d\n",daxie,xiaoxie,kongge,shuzi,other);}

編一程式,輸入一行字元,分別統計出其中大寫字母、小寫字母、空格、數字及其他字元的個數。(要求用指標

11樓:匿名使用者

#include

int main() ;

while (*p++)

printf("大寫:%d, 小寫:%d, 空格:%d, 數字:%d, 其他:%d\n", len[0],len[1],len[2],len[3],len[4]);

return 0;}

12樓:4747哦

#include

int main()

else if(*p>='a' && *p <='z')else if(*p==' ')

else if(*p>='0' && *p <='9')else

printf("大寫%d 小寫%d 空格%d 數字%d 其它%d 英文%d\n",a,b,c,d,e,a+b);

return 0;}

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

13樓:非常可愛

錯誤**:

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;}

14樓:匿名使用者

錯誤**:

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;}

15樓:匿名使用者

一、問題分析:

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

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

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

二、演算法設計:

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

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

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

4、最終輸出結果。

三、參考**:

#include

int main()

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

return 0;}

16樓:gta小雞

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

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

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

17樓:匿名使用者

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

(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;}

18樓:匿名使用者

#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;}

19樓:匿名使用者

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))+"個"

20樓:匿名使用者

#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;}

c語言怎樣統計大寫字母,小寫字母,數字,空格的的個數 這個程式錯在哪裡?為什麼老跑出來不對

小寫字母不是97到120吧,應該到122吧。還有你最後判斷的那個條件寫成了if b i 成了賦值語句而不是判斷語句。改成這樣好了 include include int main printf 大寫字母的個數為 d n小寫字母的個數 d n數字的個數 d n空格的個數 d n其他字元的個數 d n ...

c語言字串中大小寫字母轉換C語言字串中大小寫字母轉換

就是ascii碼的 來加減,字母的大寫和小自寫的ascii碼的差值是一樣的。小寫的字母ascii碼為 97 a 到 122 z 轉換成大寫字母則ascii減32,變成從65 a 到90 z 每個字母對應一個ascii碼,查ascii碼錶就可以一目瞭然。輸入字母,轉換為int型別,看其值是在什麼範圍,...

小寫字母是幾個字元?大寫字母是幾個字元?漢字呢?一般的符號又是幾個字元

gb2312 半形英文 來符自號佔位 1 全形英文 符號佔位 2 漢字佔位 2 unicode 半形英文 符號佔位 1 全形英文 符號佔位 2 漢字佔位 3 它是按字元來算的,限定你最多輸入12個字元,你輸入那個點的時候,換個輸入法,可以減少一兩個字元。一箇中文或一個大寫字母佔2個字元,小寫佔1個,...