输入一行字符,分别统计求出其中英文字母、空格、数字和其他字符的个数并输出结果。

#include<stdio.h>
int main()
{
    char str[81];
    int i ;
    int  letter,space ,num ,other ;
    char c;
    printf ("Please enter a string : ");
    gets(str); 
	letter=space=num=other=0;
    for( i= 0;str[i]!='\0'; i++)
	{
	   c=str[i];
        if((c>= 'A'&&c<='Z')|| (c>='a'&& c<='z'))
            letter ++;
        else if (c>='0' && c<='9')
            num++;
        else if ( c== ' ')
            space++;
        else other ++;
	}
    printf("In this string : letter =%d,space=%d ,num=%d,other=%d",letter ,space,num,other);
    return 0;
}
全部评论

相关推荐

05-19 15:21
已编辑
门头沟学院 Java
白火同学:你才沟通了200,说实话,北上广深杭这里面你连一座城市的互联网公司都没投满呢,更别说还有各种准一线二线城市了。等你沟通突破了三位数,还没结果再考虑转行的事吧。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务