有一篇文章,共有三行文字,每行有80个字符。要求分别统计出其中英文大写字母....

2016-06-17 16:04:17  分类: c程序设计第四版谭浩强课后答案  参与:

 有一篇文章,共有3行文字,每行有个80字符.要求分别统计出其中英文大写字母、小写字母、空格以及其它字符的个数。

以下是此题的【c源代码】,需要【c++源代码】请点击进入

#include <stdio.h>
int main()
 {int i,j,upp,low,dig,spa,oth;
  char text[3][80];
  upp=low=dig=spa=oth=0;
  for (i=0;i<3;i++)
   { printf("please input line %d:\n",i+1);
     gets(text[i]);
     for (j=0;j<80 && text[i][j]!='\0';j++)
      {if (text[i][j]>='A'&& text[i][j]<='Z')
      upp++;
       else if (text[i][j]>='a' && text[i][j]<='z')
         low++;
       else if (text[i][j]>='0' && text[i][j]<='9')
         dig++;
       else if (text[i][j]==' ')
      spa++;
       else
      oth++;
  }
   }
     printf("\nupper case: %d\n",upp);
     printf("lower case: %d\n",low);
     printf("digit     : %d\n",dig);
     printf("space     : %d\n",spa);
     printf("other     : %d\n",oth);
 return 0;
}

来源:c程序设计第四版谭浩强课后答案

本文链接:http://www.wb98.com/c/post/tanhaoqiang_6.10.html

本站文章搜索:

<< 上一篇下一篇 >>

搜索

网站分类

Tags列表

赞助商链接