|
- //实现类似于word里面统计的功能
- //3*80
- //统计大写字母、小写字母、数字、空格及其他字符数
- #include<stdio.h>
- void main()
- {int i,j;
- int c=0,l=0,n=0,s=0,o=0;
- char a[3][5];//类型指定错了
- for(i=0;i<3;i++)//首先输入30个字符
- {
- for(j=0;j<5;j++)
- {
- scanf("%c",&a[i][j]);//输入的时候不要有空格,因为空格就是一个字符
- }
- }
- for(i=0;i<3;i++)
- {
- for(j=0;j<5;j++)
- {
- if(a[i][j]>=65&&a[i][j]<=90)
- {
- c+=1;
- }
- else if(a[i][j]>=97&&a[i][j]<=122)
- {
- l+=1;
- }
- else if(a[i][j]==32)
- {
- s+=1;
- }
- else if(a[i][j]>=48&&a[i][j]<=57)
- {
- n+=1;
- }
- else
- o+=1;
- }
- }
- printf("capital=%d\n",c);
- printf("lower=%d\n",l);
- printf("number=%d\n",n);
- printf("space=%d\n",s);
- printf("other=%d\n",o);
- printf("\n");
- }
复制代码
|
|