home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tyc
/
random.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-16
|
1KB
|
43 lines
/* RANDOM.C--Demonstrates using a multidimensional array */
#include <stdio.h>
#include <stdlib.h>
/* Declare a three-dimensional array with 1000 elements */
int random[10][10][10];
int a, b, c;
main()
{
/* Fill the array with random numbers. The C library */
/* function rand() returns a random number. Use one */
/* for loop for each array subscript. */
for (a = 0; a < 10; a++)
{
for (b = 0; b < 10; b++)
{
for (c = 0; c < 10; c++)
{
random[a][b][c] = rand();
}
}
}
/* Now display the array elements 10 at a time */
for (a = 0; a < 10; a++)
{
for (b = 0; b < 10; b++)
{
for (c = 0; c < 10; c++)
{
printf("\nrandom[%d][%d][%d] = ", a, b, c);
printf("%d", random[a][b][c]);
}
printf("\nPress a key to continue, CTRL-C to quit.");
getch();
}
}
} /* end of main() */