C语言,任意输入十个字符,统计其中数字,字母
1、统计数字digits。
2、if(str[i]=='')
3、printf("单词书为:%d\n",count+1);
4、printf("请输入一行字符:>");
5、space++;
6、#defineM100
7、要统计英文字母,空格,数字和其他字符的个数,则要遇到他们加一。
8、printf("字符串中字母个数为:%d、数字个数为:%d、空格个数为:%d、其它字符个数为:%d.\n",zm,sz,kg,qt);
9、添加main主函数。
10、楼主请看这里这里决对好用的程序
11、统计其他字符others。
12、printf("请输入要统计的字符以回车结束:\n");
13、system("pause");
14、intletters=0;
15、main()
16、intother=0;
17、定义四个int类型变量letters、spaces、digits、others。
18、//判断字符是否数字
19、return0;
20、for(inti=0;i 21、while(str[i]=='')//判断连续空格 22、letters++; 23、while((c=getchar())!='\n') 24、\n数字的个数:>%d\n其他字符的个数:>%d\n",\ 25、if(isalpha(pc[i]))zm++; 26、#include 27、#include 28、else 29、统计字符letters。 30、#include 31、charpc[M]; 32、i++; 33、使用while循环。 34、intzm=0,sz=0,kg=0,qt; 35、charc; 36、elseif(c>='0'&&c<='9') 37、while(str[i++]!='\0') 38、核心代码如下 39、other++; 40、#include 41、if((c>='a'&&c<='z')||(c>='A'&&c<='Z')) 42、intdigit=0; 43、#include 44、count++; 45、intlen=strlen(pc); 46、//判断字符是否字母 47、if(isdigit(pc[i]))sz++; 48、voidmain() 49、inti=0,j,count=0; 50、charstr[20]; 51、定义一个char类型变量c。 52、intspace=0; 53、统计空格spaces。 54、{i++;} 55、使用printf打印。 56、if(pc[i]=='')kg++; 57、letters,space,digit,other); 58、qt=len-zm-sz-kg; 59、printf("\n输入字符串:"); 60、首先打开vc6.0,新建一个vc项目。 61、elseif(''==c) 62、digit++; 63、gets(str); 64、//判断字符是否空格 65、printf("字母的个数:>%d\n空格的个数:>%d\ 66、gets(pc); 67、intmain() 68、添加头文件。 69、运行程序,看看结果。
注:本文部分文字与图片资源来自于网络,转载此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请立即后台留言通知我们,情况属实,我们会第一时间予以删除,并同时向您表示歉意