
关于c语言的一道基础编程题,我是一个菜鸟新手。
编写一个c语言要求输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数,各位c语言高手帮帮忙啊,谢谢!!...
编写一个c语言 要求输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数,各位c语言高手帮帮忙啊,谢谢!!
展开
展开全部
#include "stdio.h"
main()
{char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
}
这个应该可以帮你的
main()
{char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
}
这个应该可以帮你的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询