解题思路:
首先输入一串字符,可以用gets,然后就是循环,可以用strlen,亦可以用ch[i]!='\0',就是没有结束的意思,其他就迎刃而解了
注意事项:
不要出现中文,至少是输出的时候,千万不要出现中文!!!千万不要出现中文!!!千万不要出现中文!!!
参考代码:
#include<stdio.h>
#include<string.h>
int main()
{
int a=0,b=0,c=0,d=0,i;
char ch[100];
gets(ch);
for(i=0;i<strlen(ch);i++)
{
if(ch[i]>='a'&&ch[i]<='z'||ch[i]>='A'&&ch[i]<='Z') a++;
else if(ch[i]==' ') b++;
else if(ch[i]>='0'&&ch[i]<='9') c++;
else d++;
}
printf("%d\n",a);
printf("%d\n",b);
printf("%d\n",c);
printf("%d\n",d);
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:1435 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:791 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:742 |
字符串对比 (C语言代码)浏览:1397 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:587 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:534 |
母牛的故事 (C语言代码)浏览:939 |
有关字符,字符串的输入输出函数说明浏览:477 |
C二级辅导-计负均正 (C语言代码)浏览:480 |
矩阵的对角线之和 (C语言代码)浏览:1342 |