Re: Anyone have any ideas on this one.....
- From: Michal Nazarewicz <mina86@xxxxxxx>
- Date: Mon, 10 Sep 2007 13:03:50 +0200
"joebenjamin" <guitarguy70@xxxxxxxxxxx> writes:
I am trying to write a program that will generate 100 random numbers
between 1 and 50. Using 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. Finally,I would like to print out the results as a
histogram. I have written it out and would think it would look like this.
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) ***********
I am trying to learn how to do this and I am stuck. Any suggestions would
help. Even some possible tutorials to chek out would help.
To generate random number integer from set [1, 50] you can use: "number
= rand() % 50 + 1;" (remember to initialise pseudo-random number
generator with for instance srand(time(0))).
To get bucket number you can use "bucket = (number - 1) / 5;" (so in
fact it is better to generate random integer from set [0, 49] using
"number = rand() % 50;" and then calculate bucket number using "bucket =
number / 5;").
Then you increment given bucket, ie.: "buckets[bucket]++". Buckets have
to be zeroed first of course. And when results are ready you print the
results using two nested for loops.
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
.
- Follow-Ups:
- Re: Anyone have any ideas on this one.....
- From: Richard Heathfield
- Re: Anyone have any ideas on this one.....
- References:
- Anyone have any ideas on this one.....
- From: joebenjamin
- Anyone have any ideas on this one.....
- Prev by Date: Enjoy complete book online FREE: Oracle SQL in 10 Minutes
- Next by Date: Re: initializing an int variable with all F's
- Previous by thread: Anyone have any ideas on this one.....
- Next by thread: Re: Anyone have any ideas on this one.....
- Index(es):
Relevant Pages
|
Loading