/* This is a sample C program which will ask the user for a 4X4 matrix, */ /* call a function to compute it's transpose, and output the result. */ #include /* Include the standard C library functions */ void transpose(double a[4][4], double t[4][4]); /* Declare transpose() */ void main() /* Begin the main program */ { int i, j; /* This is the variable declaration section */ double a[4][4], t[4][4]; printf("You will now enter matrix A.\n"); for (i=0; i<4; i++) /* Input matrix from keyboard */ for (j=0; j<4; j++) { printf("Enter matrix element [%d,%d]: ", i, j); scanf("%lf", &a[i][j]); } transpose(a, t); /* Call the function */ printf("The transpose of matrix A is :\n\n"); for (i=0; i<4; i++) { /* Print the results on the screen */ for (j=0; j<4; j++) printf("%lf ", t[i][j]); printf("\n"); } } /* End of main program */ /* Function to compute the transpose of "a", returning the result in "t". */ void transpose(double a[4][4], double t[4][4]) { int row, col; /* These variables are local to this function */ for (row=0; row<4; row++) for (col=0; col<4; col++) t[row][col] = a[col][row]; } /* End of function */