(C语言)用循环控制编程

来源:百度知道 编辑:UC知道 时间:2024/06/27 12:35:53
输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数?怎么编啊?各位大虾?
能否把程序发上来吗?

建议你去网上找一下 C语言100例 并去看懂会有帮助的
#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);
}

一个个判断就行了

大概就是这样吧
#include<stdio.h>
int main()
{
int zm_num=0,kg_num=0,sz_num=0,ot_num=0;
char ch;
ch=getchar();
while(ch!='\n')
{
if(ch>='0'&&ch<='9')
sz_num++;
else if(ch==' ')
kg_num++;
else if ((ch>='a&#