统计从键盘输入的一行字符中小写字母,大写字母,数字字符和其它字符的个数。
C语言实现 vs-2019
#include<stdio.h>
#include<ctype.h>
int main()
{
printf("Please input the number of string:");
int num = 0;
int num_low = 0, num_n = 0, num_c = 0;
scanf_s("%d", &num);
for (int i = 0; i < num; i++)
{
char m=getchar();
if (isdigit(m))//数字
{
num_n++;
}
if (islower(m))
{
num_low++; //小写字母
}
if (isupper(m))
{
num_c++; //大写字母
}
}
printf("数字个数:%d,小写字母个数:%d,大写字母个数:%d,其余:%d\n",num_n,num_low,num_c,num-num_c-num_low-num_n-1);
return 0;
}