从键盘上任意输入一串字符,统计该字符串中数字字符的个数。

如题所述

输入:
任意一串字符串
输出:
大写字母、小写字母、数字以及其他字符的个数。
输入样例:
abcdefg123456ABCDEFG
输出样例:
7
7
6

#include
<stdio.h>
#define
MAX
50
void
main()
{
char
a[MAX],c;
int
i=0,cb=0,cs=0,cn=0,co=0;
/*大写字母,小写字母,数字,其它*/
printf("please
input
a
string:\n");
gets(a);
while((c=a[i++])!='\0')
{

if(c>='A'&&c<='Z')

cb++;

else
if(c>='a'&&c<='z')

cs++;

else
if(c>='0'&&c<='9')

cn++;

else

co++;
}
printf("big:
%d,
small:
%d,
num:
%d,
other:
%d\n",cb,cs,cn,co);
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答