#include
#include
using namespace std;
#define NUM 1024
int main(void)
{
// 一次过可输入1024个数字
int data[NUM], n = 0;
int i, j, k;
int times[NUM], visited[NUM], max;
while (cin.peek() != '\n')
{
cin >> data[n];
++n;
if (n == NUM)
break;
}
for (i = 0; i < n; ++i)
{
visited[i] = 0;
times[i] = 1;
}
for (i = 0; i < n; ++i)
{
if (!visited[i])
{
for (j = i + 1; j < n; ++j)
{
if ((data[i] == data[j]) && !visited[j])
{
visited[j] = 1;
++times[i];
}
}
}
visited[i] = 1;
}
max = times[0];
k = 0;
for (i = 1; i < n; ++i)
{
if (times[i] > max)
{
max = times[i];
k = i;
}
}
cout << data[k] << endl;
return 0;
}
用空格分隔输入的两个数,找出其中出现次数最多的数,如果有出现最多次数相同的元素则输出最先输入的那个数
#pragma warning(disable: 4786)
#include
#include
#include
#include
指针指向一维数组,输入m个正整数,统计输出现最多的数,和出现次数
#include "stdio.h"
#include "conio.h"
int main()
{
static int m,a[100]={0},n[100],*p,*q;
printf("input m:");
scanf("%d",&m);
for(p=a;pscanf("%d",p);
getchar();
for(p=a;pn[*p]++;
q=p=n;
p++;
while (p
if(*p>*q)
q=p;
p++;
}
printf("%d %d \n",q-n,*q);
getch();
return 0;
}
#include
#include
void main()
{
int *x,n,i,j,y,t,m=0;
printf("输入个数\n");
scanf("%d",&n);
x=(int*)malloc(n*sizeof(int));
for(i=0;i
for(j=0;j
if(t>m) {m=t;y=*x;}
}
printf("次数最多的数%d 次数%d",y,m);
free(x);
}