1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 char s; 7 int letter=0,space=0,num=0,others=0; 8 scanf("%c",&s); 9 while((s=getchar())!='\n') //getchar函数可以从输入设备获得一个可显示的字符 10 { 11 if(s>='a'&&s<='z'||s>='A'&&s<='Z') 12 letter++; 13 else if(s==' ') 14 space++; 15 else if(s>=1&&s<=9) 16 num++; 17 else 18 others++; 19 } 20 printf("字母数: %d\n空格数:%d\n数字数 %d\n其它数: %d",letter,space,num,others); 21 return 0; 22 23 }
20.输入一行字符,分别统计出其中的英文字母,空格,数字和其它字符数
猜你喜欢
转载自www.cnblogs.com/spore/p/10359267.html
今日推荐
周排行