解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <string.h>
int main()
{
char str[1000];
gets(str);
count(str);
}
int count(char str[1000])
{
int number, space, letter, others, n, i;
n = strlen(str);
number = 0;
space = 0;
letter = 0;
others = 0;
for(i = 0 ; i < n ; i ++)
{
if('a' <= str[i] && str[i] <='z' || 'A' <= str[i] && str[i] <= 'Z')
{
letter ++;
}
else if('0' <= str[i] && str[i] <= '9')
{
number ++;
}
else if(str[i]==' ')
{
space ++;
}
else
{
others++;
}
}
printf("%d %d %d %d",letter, number, space, others);
}
0.0分
0 人评分
C二级辅导-计负均正 (C语言代码)浏览:598 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:943 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:495 |
【绝对值排序】 (C语言代码)浏览:717 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:449 |
C语言考试练习题_一元二次方程 (C语言代码)浏览:576 |
水仙花 (C语言代码)浏览:1052 |
母牛的故事 (C语言代码)浏览:478 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:560 |
求教大神。。。。1063,统计字符。浏览:11685 |