输入一个字符串(包括若干个字符和数字),统计其中大写字母、小写字母、数字和其他字符的个数。
#include <stdio.h>
int main ()
{
char a[100];
int sum0=0, suma=0, sumA=0,other=0;
gets(a);
char *p;
for (p = a; *p != '\0'; p++)
{
if (*p >= '0' && *p <= '9')
sum0 += 1;
else if (*p >= 'a' && *p <= 'z')
suma += 1;
else if (*p >= 'A' && *p <= 'Z')
sumA += 1;
else
other+=1;
}
printf ("大写字母:%d\n小写字母:%d\n数字:%d\n其他字符:%d\n",sumA,suma,sum0,other);
return 0;
}
#include <stdio.h>
int main()
{
int i=0;
int a=0,b=0,c=0,d=0;
char s[1000]={0};
gets(s);
while(s[i] != 0)
{
if(s[i] >= '0' && s[i] <= '9')
a++;
if(s[i] >='A' && s[i] <='Z')
b++;
if(s[i] >='a' && s[i] <='z')
c++;
else
d++;
i++;
}
printf("大写字母 %d个,小写字母%d个,数字%d个,其它字符%d个\n",b,c,a,d);
return 0;
}