Originally Posted by
timbean
Hello, My program is to generate a two dimensional array of random integers between 0 and 40, each row of this array is X, Y, and Z of a plane. I dont have a clue how to go about this program. This is what i have so far. Can someone let me know if i'm doing this correctly? If not, how should I go about doing it?
Code:
#include <time.h>
#include <math.h>
#include <stdlib.h>
double array[][][5]; <-- remove this
int main(void)
{
double x,y,z; <-- counters should be type int
double array[2][4][5];
srand(time(NULL));
for(x=0;x<40;x++) <-- This should be x <2
{
for(y=0;y<40;y++) <-- this should be y < 4
{
for(z=0;z<40;z++) <-- this should be z < 5
{
array[x][y][z] = <--- call rand() here
}
}
}
When writing C code always be aware of the sizes of your arrays. If you overrun the boundaries bad --undefined-- stuff is very likely to happen.