标题: c语言统计大写字母、小写字母、数字、空格及其他字符数 [打印本页]

作者: liuda    时间: 2015-1-22 02:26
标题: c语言统计大写字母、小写字母、数字、空格及其他字符数
  1. //实现类似于word里面统计的功能
  2. //3*80
  3. //统计大写字母、小写字母、数字、空格及其他字符数
  4. #include<stdio.h>
  5. void main()
  6. {int i,j;
  7. int c=0,l=0,n=0,s=0,o=0;
  8. char a[3][5];//类型指定错了
  9.   for(i=0;i<3;i++)//首先输入30个字符
  10.   {
  11.     for(j=0;j<5;j++)
  12. {
  13.         scanf("%c",&a[i][j]);//输入的时候不要有空格,因为空格就是一个字符
  14. }
  15.   }
  16.    for(i=0;i<3;i++)
  17.   {
  18.     for(j=0;j<5;j++)
  19. {
  20.   if(a[i][j]>=65&&a[i][j]<=90)
  21.   {
  22.   c+=1;
  23.   }
  24.   else if(a[i][j]>=97&&a[i][j]<=122)
  25.   {
  26.   l+=1;
  27.   }
  28.        else if(a[i][j]==32)
  29.   {
  30.   s+=1;
  31.   }
  32.   else if(a[i][j]>=48&&a[i][j]<=57)
  33.   {
  34.   n+=1;
  35.   }
  36.   else
  37.   o+=1;
  38. }
  39.   }
  40. printf("capital=%d\n",c);
  41. printf("lower=%d\n",l);
  42. printf("number=%d\n",n);
  43. printf("space=%d\n",s);
  44. printf("other=%d\n",o);
  45. printf("\n");
  46. }
复制代码







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1