From eb6bcbdcddc0ef314f6d0db133592a54dace517b Mon Sep 17 00:00:00 2001 From: Steven Schronk Date: Tue, 29 Dec 2009 19:49:59 -0600 Subject: [PATCH] Added example cbd_rand_dist. Generates random numbers and displays distribution. --- cbd_rand_dist.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 cbd_rand_dist.c diff --git a/cbd_rand_dist.c b/cbd_rand_dist.c new file mode 100644 index 0000000..6b395d6 --- /dev/null +++ b/cbd_rand_dist.c @@ -0,0 +1,29 @@ +/* +* User inputs integer number. This number represents the count of random numbers to generate. +* Each of these numbers is counted in an array of 10 integers. +* When the number generation is complete, a chart of the distribution is sent to stdout. +*/ + +#include +#include + +int main() +{ + int count; + int tally[10] = { '0' }; + + printf("Number of Random Integers to Generate: "); + scanf("%d", &count); + while(count > 0) + { + tally[rand()%10]++; + --count; + } + + while(count < 10) + { + printf("%d->%d\n", count, tally[count]); + ++count; + } + return 0; +} -- 2.11.4.GIT