#include<stdio.h>
int main()
{
char str[20];
int count[10]={0},i,max;
printf("请输入20个整数:");
gets(str);
for(i=0;str[i]!='\0';i++)
{
if(str[i]>='0'&&str[i]<='9')
{
count[str[i]-'0']+=1;
}
}
for(i=0;i<10;i++)
{
if(count[i]>count[i+1])
{
max=count[i];
i++;
}
else if(count[i]<count[i+1])
{
max=count[i+1];
i++;
}
printf("出现频率最高的元素值是%c\n",'0'+i);
printf("出现次数为%d",max);
}
return 0;
}
#include <iostream>
#define N1 1000
int b[N1] = { 0 };
int max;
int index = 0;
int i, j, n;
void top(int a[], int size)
{
for (i = 0; i < size; i++)
{
for (j = 0; j < size; j++)
{
if (a[i] == a[j])
{
b[i]++;
}
}
}
max = b[0];
index = 0;
for (j = 1; j < size; j++)
{
if (max < b[j])
{
max = b[j];
index = j;
}
}
printf("%d,%d\n", a[index], max);
}
int main()
{
int a[N1] = { 6,3,3,6,6,-2,3,7,3 };
top(a, 9);
return 0;
}