编写程序,输入一行文字,统计其中大写字母,小写字母、空格以及数字符号的个数

如题所述

#include<stdio.h>

void main()

{

 char s[100];

 int i,up=0,low=0,sp=0,digit=0,other=0; 

 gets(s);

 for(i=0;s[i];i++)

   if(s[i]>='A'&&s[i]<='Z')up++;

     else if(s[i]>='a'&&s[i]<='z')low++;

       else if(s[i]>='0'&&s[i]<='9')digit++;

         else if(s[i]==' ')sp++;

           else other++;

 printf("up=%d\nlow=%d\nsp=%d\ndigit=%d\nother=%d\n",up,low,sp,digit,other);

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-31
采用ascii码识别啊,大写小写,数字分别在不同段,空格就一个数值
依次读入字符,计算其ascii码值,当其值在48至57之间时为数字,在65到90之间时为大写字母,在97至122直接时为小写字母,等于32时为空格。
第2个回答  2013-12-31
下载手机金山软件就可以了,反正我的是这样
相似回答