/* by Mark A. Sheldon, February 2005 */ #include #include #define FAILURE -1 int main(int argc, char *argv[]) { double **matrix; int rows, cols, i, j; if (scanf("%d %d", &rows, &cols) != 2) { fprintf(stderr, "Unable to read matrix size from start of file\n"); exit(FAILURE); } matrix = (double **) calloc(rows, sizeof(double *)); if (matrix == NULL) { fprintf(stderr, "Unable to alloc spine\n"); exit(FAILURE); } for (i = 0; i < rows; ++i) if ((matrix[i] = calloc(cols, sizeof(double))) == NULL) { fprintf(stderr, "Unable to malloc row\n"); exit(FAILURE); } for (i = 0; i < rows; ++i) { for (j = 0; j < cols; ++j) { matrix[i][j]= (double)i + (double)j; } } for (i = 0; i < rows; ++i) { for (j=0; j