編寫程序,從鍵盤上輸入一串字符,以回車結束,輸出其中大寫字母,小寫字母,數字字符和其他字符的個數。
1 回答
已采納
望遠
TA貢獻1017條經驗 獲得超1032個贊
#include<stdio.h>
void?main()
{
char?str[100];
int?i,number=0,A=0,a=0,other=0;
printf("請輸入一行字符串:");
gets(str);
for(i=0;str[i]!='\0';i++)
{
if(str[i]>='0'&&str[i]<='9')
number++;
else?if(str[i]>='a'&&str[i]<='z')
a++;
else?if(str[i]>='A'&&str[i]<='Z')
A++;
else
other++;
}
printf("大寫字母:%d個,小寫字母:%d個,數字:%d個,其他%d個\n",
A,a,number,other);
}- 1 回答
- 0 關注
- 1286 瀏覽
添加回答
舉報
0/150
提交
取消
