呋麻滴鼻液3岁儿童用量:C语言编程:输入一行字符,统计出其中英文字母、空格、数字和其他字符的个数

来源:百度文库 编辑:高校问答 时间:2024/04/30 01:00:39

呵呵,下面是C的,其实这里输入的时候输入空格就被认为输入中止,所以计算空格没意义,所以目前有个假设空格能输入哈

#include<stdio.h>
void main()
{ int nE=0,nS=0,nN=0,nO=0,i=0;
char a[1000];
scanf("%s",a);
while (a[i]!='\0') {
if (a[i]<='z' && a[i]>='a' || a[i]<='Z' && a[i]>='A')
nE++;
else
{if (a[i]<='9' && a[i]>='0')
nN++;
else
{if (a[i]==' ')
nS++;
else
nO++;
}
}
i++;

}
printf("%d\n%d\n%d\n%d",nE,nS,nN,nO);
}

to: wangtk1982

如果要计空格,你可以用gets()函数
并且也没有必要用数组

直接getchar();用while来循环