/*编一函数,功能为统计字符串中各个字母(不区分大、小写)出现的频率,同时找出频率出现最高的字母及次数,假设出现次数最多的字母只有一个。函数形式为:
void freq(char s[],int p[],char &chmax,int &max):*/
#include<iostream>
#include<string.h>
using namespace std;
int freq(char s[],int p[],char &chmax,int &max)
{char *q=s;
int i,j;
while(*q)
{if(*q<='z'&&*q>='a'||*q<='Z'&&*q>='A')
{if(*q>='a')
p[*q]++;
else
p[*q+32]++;
if(p[*q]>max)
{max=p[*q];
chmax=*q;}
q++;}
}
return 0;
}
int main()
{char ch[100]="";char chmax;int max;int i;
int sum[100]={0};
gets_s(ch);
freq(ch,sum,chmax,max);
for(i=1;ch[i]!='\0';i++)
if(sum[i])
cout<<ch[i]<<"----"<<sum[i]<<endl;
cout<<"出现频率最高的数为:"<<endl;
cout<<chmax<<"----"<<max<<endl;
system("pause");
return 0;
}
为什么跑不了,这是什么回事呢?谢谢