I wrote this program to generate a keyboard determined random numbers.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int amount, aleatory_numbers;
int array[70];
int counter=0;

int generator ()
printf ("Introduce the amount of numbers that you wish: ");
scanf ("%d", &amount);
srand ( time(NULL) );
aleatory_numbers = rand() % 49 + 1;
printf ("%d", array[counter]);
while (counter!=amount);

return array[counter],counter;

int main ()

It works, but now I need to display on screen the frequency of each numbers of the array. How can I do that? I've tried lots of things, but I can't do that.


Well i guess now you could use another variable to count how many times a particular number is repeated in the data set and then could get the percentage of the occurence of that particular number .

You should however post your tries on doing this and we can help you out from there.

Just in passing:

First return array[counter],counter; is an awful way to say return counter .
The code does not return array[counter] in anyway.


If I were to enter 100 as the number of numbers. then your code would break since the array is only 70 big.


I think that you would prefer to enter a huge number of random and then obtain the number of 1s, 2s etc. You do not care about the order (yet) . So try collecting the statisics first. For example if your random number part only generated numbers between 1 and 10.
if you did this

int array[11];       // arrays are 0->10

// set array elements to zero here. 

  N = rand() % 10 + 1;

// now print the array.

you have a nice set of distributions because array[1] is increased each time N becomes 1.

This article has been dead for over six months. Start a new discussion instead.