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