/* This program reads m, n, and an m-by-n matrix. For example: 2 3 3.1 4.1 5.9 2.6 5.3 5.8 It prints n, m, and the transpose of the matrix. For example: 3 2 3.1 2.6 4.1 5.3 5.9 5.8 It dynamically allocates space for the matrix, up to 1000000 bytes. */ #include #include void die_read(void) { printf("scanf failed\n"); exit(1); } void die_nomem(void) { printf("out of memory\n"); exit(1); } int main(void) { unsigned int m; unsigned int n; unsigned int i; unsigned int j; float bytes; double *x; if (scanf("%u",&m) < 1) die_read(); if (scanf("%u",&n) < 1) die_read(); bytes = m; bytes *= n; bytes *= sizeof(double); if (bytes >= 1000000) die_nomem(); x = (double *) malloc(bytes); if (!x) die_nomem(); for (i = 0;i < m;++i) for (j = 0;j < n;++j) if (scanf("%lf",x + i * n + j) < 1) die_read(); printf("%u %u\n",n,m); for (j = 0;j < n;++j) for (i = 0;i < m;++i) printf("%f%c",x[i * n + j]," \n"[i == m - 1]); return 0; }