输入n个数,怎样把出现次数最多的那个数找出来 输入n个数,怎样把出现次数最多的那个数找出来

来源:百度知道 编辑:UC知道 时间:2024/06/16 08:25:10
c++语言

指针指向一维数组,统计输出现最多的数,和出现次数

#include "stdio.h"
#include "conio.h"
int main()
{
static int a[10]={0},n[10],*p,*q;
for(p=a;p<a+10;p++)
scanf("%d",p);
getchar();
for(p=a;p<a+10;p++)
n[*p]++;
q=p=n;
p++;
while (p<n+10)
{
if(*p>*q)
q=p;
p++;
}
printf("%d %d \n",q-n,*q);
getch();
return 0;
}