Monday, 18 July 2016

Row & Column Major



#include<stdio.h>
#include<time.h>
int main()
{
    int i,j,c=1,n=100,a[n][n];

    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            a[i][j]=c;
            c++;
        }
    }

    clock_t begin = clock();
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            printf("%d\t",a[i][j]);
        }
        printf("\n");
    }
    clock_t end = clock();
    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;


    clock_t s = clock();
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            printf("%d\t",a[j][i]);
        }
        printf("\n");
    }

    clock_t e = clock();
    double time_spent2 = (double)(e - s) / CLOCKS_PER_SEC;

    printf("Row time = %f\n",time_spent);
    printf("Column time = %f\n",time_spent2);
    return 0;
}



1 comment: