第1个回答 2009-12-30
为了提高编程的能力,我给你提供的答案为输出三行的字符(你可以改为输入一行的)!
#include <stdio.h>
void main()
{
int i,j,upp,low,dig,spa,oth;
char text[3][80];
upp=low=dig=spa=oth=0;
for (i=0;i<3;i++)
{
printf("please input line %d:\n",i+1);
gets(text[i]);
for (j=0;j<80 && text[i][j]!='\0';j++)
{
if (text[i][j]>='A'&& text[i][j]<='Z')
upp++;
else if (text[i][j]>='a' && text[i][j]<='z')
low++;
else if (text[i][j]>='0' && text[i][j]<='9')
dig++;
else if (text[i][j]==' ')
spa++;
else
oth++;
}
}
printf("\nupper case: %d\n",upp);
printf("lower case: %d\n",low);
printf("digit : %d\n",dig);
printf("space : %d\n",spa);
printf("other : %d\n",oth);
}
第2个回答 2009-12-30
void main()
{int i,s=0,b=0,c=0,d=0,e=0;
char a[50];
gets(a);
for(i=0;i<50;i++)
{
if(a[i]>='A'&&a[i]<='Z')s++;
else
if(a[i]>='a'&&a[i]<='z')b++;
else
if(a[i]>=1&&a[i]<=9)c++;
else
if(a[i]=='')d++;
else e++;}
printf("A-Z:%d a-z:%d 1-9:%d space:%d others:%d ",s,b,c,d,e);
}