解题思路:
用最传统的方法做吧,逐一判断。
注意事项:对数字的判断,引用单引号。
参考代码:
#include<stdio.h>
int main()
{
char a[100];
int i;
gets(a);
int character=0,number=0,space=0,other=0;
for(i=0;a[i]!='\0';i++)
{
if(a[i]>='a'&&a[i]<='z'||a[i]>='A'&&a[i]<='Z')
character++;
else if(a[i]>='0'&&a[i]<='9') //此处的单引号少了,条件就无效了
number++;
else if(a[i]==' ')
space++;
else
other++;
}
printf("%d %d %d %d",character,number,space,other);
return 0;
}
0.0分
0 人评分
C语言训练-字符串正反连接 (C语言代码)浏览:622 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:536 |
C语言训练-自由落体问题 (C语言代码)浏览:1736 |
【绝对值排序】 (C语言代码)浏览:713 |
妹子杀手的故事 (C语言代码)浏览:1219 |
C语言训练-求PI* (C语言代码)浏览:613 |
WU-格式化数据输出 (C++代码)浏览:1199 |
WU-整数平均值 (C++代码)浏览:1240 |
C语言程序设计教程(第三版)课后习题6.6 (C++代码)浏览:627 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:567 |