I was able to create the code where the frequency of the number that was repeated the most is printed, but I need the frequency of each number, however I cannot do it. Anyone have an idea how to do it?
Write a program that randomly generates 100 numbers in the range of the set from 1 to 20, and then generates a list with the frequency of each number.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
srand(time(0));
int arreglo[100];
int i,j, c,c1, frecuencia;
for(i=0;i<=99;i++) {
arreglo[i] =rand()% 20+1 ;
printf("\n %i ", arreglo[i]);
}
c1=-1;
for(i=0; i<=100; i++)
{
c=0;
for(j=0; j<=99; j++)
{
if(arreglo[i]==arreglo[j])
{
c=c+1;
}
}
if(c>c1)
{
frecuencia=arreglo[i];
c1=c;
}
}
printf("\n La frecuencia es de:%i", frecuencia);
return 0;
}
1 Answers