#include <stdioh>
#include <stdlibh>
#define MAX 100
int main()
{
char str[MAX]; // 输入的字符串,最大长度是MAX-1,因为有一个字符串结束符
int i = 0, count[52] = { 0 }; // count 数组用来存储各个字母出现的次数
scanf("%s", str);
while(str[i] != '\0') {
if (str[i] >= 'a' && str[i] <= 'z') { // 统计小写字母
count[str[i] - 97 + 26]++;
}
if (str[i] >= 'A' && str[i] <= 'Z') { // 统计大写字母
count[str[i] - 65]++;
}
i++;
}
for (i = 0; i < 26; i++) { // 输出大写字母信息
if (count[i] != 0)
printf("%c\t%d\n", i + 65, count[i]); // 只输出不为零的数据
}
for (i = 26; i < 52; i++) { // 输出小写字母信息
if (count[i] != 0)
printf("%c\t%d\n", i + 97 - 26, count[i]);
}
return 0;
}
以上就是关于编写一个C语言程序:从键盘读入一行文本,统计每个英文字母出现的次数。全部的内容,包括:编写一个C语言程序:从键盘读入一行文本,统计每个英文字母出现的次数。、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)