数fun的功能是:找出形参s所指子待 中出现频率最高的子母(不区分大小写),并统计出其出现的次数。
例如:形参s所指的字符串为:
程序执行后的输出结果为:
letter 'a':3 times
letter 's':3 times
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void fun(char *s){
int k[26] = {0}, n, i, max = 0;
char ch;
while (*s) {
if (isalpha(*s)) {
ch = tolower(*s);
n = ch - 'a';
k[n] += 1;
}
s++;
if (max < k[n])
max = k[n];
}
printf("After count :\n");
for (i = 0; i < 26; i++)
if (k[i] == max)
printf("letter \'%c\' : %d times\n", i + 'a', k[i]);
}
int main(){
char s[81];
printf("Enter a string:");
gets(s);
fun(s);
}
程序结果: