2024-09-18 00:05:18
程序可按照以下流程执行:
1、输入字符串
2、对于字符串中的每一个字符,判断其为何种类型,并将相应的累加计数器加1。对于大小写字母和数字,可通过一个范围(大于等于某值和小于等于某值)来判断
代码如下:
#include <string.h>
#include <stdio.h>
int main()
{
char str[1000];
int lowAlpha, upAlpha, num, other;
int i;
lowAlpha = upAlpha = num = other = 0;
for (i = 0; i < strlen(str); i++)
if (str[i] >= 'a' && str[i] <= 'z')
lowAlpha++;
else if (str[i] >= 'A' && str[i] <= 'Z')
upAlpha++;
else if (str[i] >= '0' && str[i] <= '9')
num++;
else
other++;
printf("Upper:%d, Lower:%d, Number:%d, Other:%d\n", upAlpha, lowAlpha, num, other);
return 0;
}