解题思路:使用字符处理函数
注意事项:源文件包含头文件<ctype.h>
参考代码:
#include <stdio.h>
#include<ctype.h>
#define N 1000
int main()
{
char a[N];
int i,letter=0,number=0,space=0,other=0;
gets(a);
for(i=0;a[i]!='\0';i++)
{
if(isalpha(a[i]))
letter++;
else if(isdigit(a[i]))
number++;
else if(a[i]==' ')
space++;
else
other++;
}
printf("%d %d %d %d",letter,number,space,other);
return 0;
}
0.0分
1 人评分
不容易系列 (C语言代码)浏览:664 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:578 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:1419 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:879 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:552 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:851 |
WU-输出正反三角形 (C++代码)浏览:1018 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:916 |
震宇大神的杀毒软件 (C语言代码)浏览:1079 |
剪刀石头布 (C语言代码)浏览:1432 |