用C语言解决以下问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 02:06:00
输入一行文字,找出其中大写字母、小写字母、空格、数字以及其他字符各有多少?

#include<stdio.h>
#include<string.h>
int main()
{
int letter_A=0,letter_a=0,space=0,num=0,other=0,i,l;
char s[1001];
gets(s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]==' ') space++;
else if(s[i]<='Z' && s[i]>='A') letter_A++;
else if(s[i]<='z' && s[i]>='a') letter_a++;
else if(s[i]<='9' && s[i]>='0') num++;
else other++;
}
printf("da xie %d\nxiao xie %d\n shu zi %d\n kong ge %d\nqi ta %d\n",letter_A,letter_a,num,space,other);
}

我记得老谭那本C语言教材上有例程吧。

#include<string.h>
#include<stdio.h>
void main()
{
char c;
int w=0,x=0,y=0,z=0,a=0;
while((c=getchar())!='\n')
{
if(c>='a'&& c<='z')
w++;
else if(c>='A' && c<='z')
a++;
else if (c