Added example cbd_rand_dist. Generates random numbers and displays distribution.
authorSteven Schronk <[email protected]>
Wed, 30 Dec 2009 01:49:59 +0000 (29 19:49 -0600)
committerSteven Schronk <[email protected]>
Wed, 30 Dec 2009 01:49:59 +0000 (29 19:49 -0600)
cbd_rand_dist.c [new file with mode: 0644]

diff --git a/cbd_rand_dist.c b/cbd_rand_dist.c
new file mode 100644 (file)
index 0000000..6b395d6
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+
+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;
+}