c语言编程程序_编程程序,用c语言编程

原问题:编程程序,用c语言编程
分类:编程开发 > 最后更新时间:【2016-12-24 19:05:45】
问题补充:输入一行字符,以回车键做结束标志,分别统计出大写字母、小写字母、数字字符、空格和其他字符的个数

最佳答案

#include <stdio.h>

#include <string.h>

int main()

{

char s[100];

gets(s);

int lenth = strlen(s);

int i;

int big, small, number, space, els;

big = small = 0;

number = space = els = 0;

for( i = 0;i < lenth;i++ )

{

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

big++;

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

small++;

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

number++;

else if( s[i]==' ' )

space++;

else

els++;

}

printf("大写字母个数为:%d\n",big);

printf("小写字母个数为:%d\n",small);

printf("数字个数为:%d\n",number);

printf("空格个数为:%d\n",space);

printf("其他字符个数为:%d\n",els);

return 0;

}

最佳答案由网友  Kai_King  提供
公告: 为响应国家净网行动,部分内容已经删除,感谢网友理解。
5

分享到:

其他回答

其它网友回答:
void func(const char *str)

其它网友回答:
{

其它网友回答:
   int tmp[256] = { 0 };

其它网友回答:
   while (*str != '\0')    ++ tmp[*str++];

其它网友回答:
}

其它网友回答:

其它网友回答:
上面的tmp中已经统计出所有字符的个数,某字符的个数就是tmp对应的下标元素,比如空格符的个数就是tmp[' '],逗号的个数就是tmp[','],只需要再对其统计大、小写字母和数字即可


追答:
大写统计: int sum = 0; for (char c = 'A'; c <= 'Z'; ++c) sum += tmp[c]; 其它的统计类似
    推荐