-
No problem. Sorry that my previous replies appeared to confuse you more than help you. Actually the code can be shortened quite abit by merging the loops -
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
/*****************************************
/* definitions *
/*****************************************
#define NUM_ELEM 100
#define RANGE 30
/***************************
/* BEGIN OF MAIN *
/***************************
int main()
{
int array1[NUM_ELEM]={0}; /* declare/initilize arrays *
int array2[RANGE]={0};
int i; /* declare int variables *
int mode=0;
srand((unsigned)time(NULL)); /* seed random number *
/* generator *
printf("here is the array created\n");
for (i=0;i<NUM_ELEM;i++)
{
array1[i]=rand()%RANGE+1;
printf("%2d ",array1[i]);
if ((i+1)%20==0)
printf("\n");
array2[array1[i]-1]++;
if (array2[array1[i]-1]>mode)
mode = array2[array1[i]-1];
}
printf("\n\n");
for(i=0;i<RANGE;i++)
{
if(array2[i]==mode)
printf("number: %d\toccurance: %d\n",i+1,array2[i]);
}
return 0;
}