c语言编程程序_编程程序,用c语言编程
最佳答案
#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;
}
其他回答
其它网友回答:
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]; 其它的统计类似