Below are two programs that are almost identical except that I switched the i and j variables around. They both run in different amounts of time. C
i
j
This line the culprit :
x[j][i]=i+j;
The second version uses continuous memory thus will be substantially faster.
I tried with
x[50000][50000];
and the time of execution is 13s for version1 versus 0.6s for version2.