Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Last active February 12, 2019 12:12
Show Gist options
  • Save thomwiggers/935d927f1b0fca71e38cc881db19f54d to your computer and use it in GitHub Desktop.
Save thomwiggers/935d927f1b0fca71e38cc881db19f54d to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int i,j;
unsigned long long **m;
unsigned long long **mt;
while(1)
{
// allocate matrix m
m = malloc(1000*sizeof(unsigned long long*));
if(m == NULL) return -1;
for(i=0;i<1000;i++)
{
m[i] = malloc(1000*sizeof(unsigned long long));
if(m[i] == NULL) return -1;
}
// allocate matrix mt
mt = malloc(1000*sizeof(unsigned long long*));
if(mt == NULL) return -1;
for(i=0;i<1000;i++)
{
mt[i] = malloc(1000*sizeof(unsigned long long));
if(mt[i] == NULL) return -1;
}
for(i=0;i<1000;i++)
for(j=0;j<1000;j++)
m[i][j] = 1000*i+j;
// transpose matrix m, write to mt
for(i=0;i<1000;i++)
for(j=0;j<1000;j++)
mt[i][j] = m[j][i];
// free matrices m and mt
free(m);
free(mt);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment