Here is my issue if anyone can help.
I am trying to write a program that will generate 100 random numbers between 1 and 50. With these numbers, I want to generate a list that will tell the number of random numbers that fell between 1-5, 6-10, 11-15, 16-20, ... , and 46-50. Print out the results as a histogram. I am hoping to get results such as:
1-5 (11) ***********
6-10 (8) ********
11-15 (12) ************
16-20 (9) *********
21-25 (10) **********
26-30 (11) ***********
31-35 (7) *******
36-40 (8) ********
41-45 (13) *************
46-50 (11) ***********
Here is my attempt so far, not so good.....
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int d1, d2;
int a[100];
for(i = 1; i <= 50; i = i + 1)
a[i] = 0;
for(i = 0; i < 100; i = i + 1)
{
d1 = rand() % 49 + 1;
a[d1] = a[d1] + 1;
}
for(i = 1; i <= 50; i = i + 1)
{
printf("%d: %d\t", i, a[i]);
printf("*", a[i]);
printf("\n");
}
printf("Please press ENTER to terminate.\n");
getchar ();
return 0;
}
I hope someone can help, even if there is a tutorial or anything.