Solution for Exercise 11-17

ex1117

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

int main()
{
    int r,a,b;

    puts("100 Random Numbers");
    for(a=0;a<20;a++)
    {
        for(b=0;b<5;b++)
        {
            r=rand();
            printf("%d\t",r);
        }
        putchar('\n');
    }
    return(0);
}

Output

16807    282475249	1622650073	984943658	1144108930 
470211272 101027544 1457850878 1458777923 2007237709
823564440 1115438165 1784484492 74243042 114807987
1137522503 1441282327 16531729 823378840 143542612
896544303 1474833169 1264817709 1998097157 1817129560
1131570933 197493099 1404280278 893351816 1505795335
1954899097 1636807826 563613512 101929267 1580723810
704877633 1358580979 1624379149 2128236579 784558821
530511967 2110010672 1551901393 1617819336 1399125485
156091745 1356425228 1899894091 585640194 937186357
1646035001 1025921153 510616708 590357944 771515668
357571490 1044788124 1927702196 1952509530 130060903
1942727722 1083454666 1108728549 685118024 2118797801
1060806853 571540977 194847408 2035308228 158374933
1075260298 824938981 595028635 1962408013 1137623865
997389814 2020739063 107554536 1635339425 1654001669
1777724115 269220094 34075629 1478446501 1864546517
1351934195 1581030105 1557810404 2146319451 1908194298
500782188 657821123 753799505 1102246882 1269406752
1816731566 884936716 1807130337 578354438 892053144

Notes

* Of course, the random values you see will be different from the output shown above - or not.

* Some compilers offer the random() function that's "improved" over rand(). The random() function supposedly does the same thing as rand(), but it returns a long int value instead of an int.