源代码:
#include<stdio.h>//头文件
int main()//主函数
{
int total();
char str[45];
gets(str);
total(str);
return 0;
}
int total(char str[])
{
int number = 0, letter = 0, space = 0, other = 0;
int i;
char a;
for (i = 0; i <= strlen(str); i++)
{
a = str[i];
if (0 <= a <= 9)
number++;
else if (a == ' ' && a != '/n')
space++;
else if ('a' <= a <= 'z' || 'A' <= a <= 'Z')
letter++;
else
other++;
}
printf("字母有%d个\n数字有%d个\n其他有%d个\n空格有%d个\n", letter, number, other, space);
}
运行结果不对