code cleanup - Cleaning Up User Defined Matrix -
i'm doing project in class involves creating user defined matrix , displaying both matrix , transpose. created source file works, think cleaned bit. have far:
int nrow; int ncol; int n = 0; int m = 0; printf ("please enter number of rows.\n"); scanf ("%d", &nrow); printf ("please enter number of columns.\n"); scanf ("%d", &ncol); printf ("please enter desired matrix values.\n"); int matrix[nrow][ncol]; int mrow = nrow; int mcol = ncol; while (ncol > 0) { while (nrow > 0) { scanf ("%d", &matrix[n][m]); n++; nrow--; } ncol--; n = 0; m++; nrow = mrow; } ncol = mcol; nrow = mrow; m = 0; n = 0; printf ("original matrix\n"); while (ncol > 0) { while (nrow > 0) { printf ("%3d", matrix[n][m]); n++; nrow--; } ncol--; n = 0; m++; nrow = mrow; printf ("\n\n"); } printf ("the transpose of matrix is:\n"); ncol = mcol; nrow = mrow; m = 0; n = 0; while (nrow > 0) { while (ncol > 0) { printf ("%3d", matrix[m][n]); n++; ncol--; } nrow--; n = 0; m++; ncol = mcol; printf ("\n\n");
thanks in advance!!!
Comments
Post a Comment