I am trying to define a 2D array of 1000 by 1000 ints and then test which transversal
method is faster (row major or column major).
I have this written
#include <stdio.h>
#include <time.h>
int main()
{
clock_t start, end;
double elapsed;
start=clock();
int array[1000][1000];
int row, col;
for(row=0; row<1000; row++)
for(col=0; col<1000; col++)
array[row][col]= row*col;
end=clock();
elapsed= (end-start)/(double)CLOCKS_PER_SEC;
printf("Seconds elapsed = %f\n", elapsed);
printf("%d\n", array);
return 0;
The program compiles, but causes an exception while running. I've tried with smaller
int sizes (10, 100, etc) but they all yield times of 0.000000 seconds, like the array is already optimized.
I am just trying to populate each index in the array with some value so I can run this test. So my question is, can anybody suggest a way that I can populate the 2D array, with each index having some value (e.g. any number between 1 and 100) and calculate the time it takes to execute?