输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少
- 代码如下:
#include<stdio.h>
int main()
{
char a[100],*p=a;
int k=0,m=0,l=0,n=0,other=0;
printf("please input a:\n");
gets(a);
p=a;
while(*p!='\0'){
if(*p==' ')k++;
else if(*p>='a'&& *p<='z') m++;
else if(*p>='A'&& *p<='Z') l++;
else if(*p>='0'&& *p<='9') n++;
else other++;
p++;
}
printf("kongge=%d,xiaoxie=%d,daxie=%d,shuzi=%d,other=%d",k,m,l,n,other);
return 0;
}
- 运行结果如下: