#include <stdio.h>
int main() {
char c;
int word, blank, number, other,i,n;
word = 0;
blank = 0;
number = 0;
other = 0;
printf("请输入一个正整数n:\n");
scanf("%d",&n);
printf("请输入一串字符:\n");
for (i = 0; i <= n; i++) {
scanf("%c", &c);
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
word++;
} else if (c == ' ') {
blank++;
} else if (c >= '0' && c <= '9') {
number++;
} else {
other++;
}
}
printf("该字符中英文字母word=%d,空格有blank=%d,数字有number=%d,其他字符有other=%d",word,blank,number,other);
return 0;
}
for循环统计字母、数字、空格数量
最新推荐文章于 2024-09-14 21:41:07 发布