C语言
统计字符串中控制字符,数字字符,小写英文字符,大写英文字符和其他字符的个数。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 100
int main()
{
char str[MAX];
int a=0, b=0, c=0, d=0,other=0;
printf("输入字符串:\n");
scanf("%s", &str[MAX]);
for (int i = 0; i < MAX; i++)
{
if (islower(str[i]))
{
a++;
}
else if (isupper(str[i]))
{
b++;
}
else if (isdigit(str[i]))
{
c++;
}
else if (iscntrl(str[i]))
{
d++;
}
else
{
other++;
}
break;
}
printf("有%d个控制字符\n", d);
printf("有%d个数字字符\n", c);
printf("有%d个大写字母\n", b);
printf("有%d个小写字母\n", a);
printf("有%d个其他字符\n", other);
return 0;
}