12345678910111213141516171819202122232425262728293031323334353637 |
- #include <stdio.h>
- void transpose_matrix(int matrix[3][3]) {
- int temp;
- int i,j;
- for (i = 0; i < 3; i++) {
- for (j = i + 1; j < 3; j++) {
- temp = matrix[i][j];
- matrix[i][j] = matrix[j][i];
- matrix[j][i] = temp;
- }
- }
- }
- int main() {
- int matrix[3][3];
- int i,j;
- // Input matrix elements
- for (i = 0; i < 3; i++) {
- for (j = 0; j < 3; j++) {
- scanf("%d", &matrix[i][j]);
- }
- }
- // Transpose the matrix
- transpose_matrix(matrix);
- // Output transposed matrix
- for (i = 0; i < 3; i++) {
- for (j = 0; j < 3; j++) {
- printf("%d ", matrix[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
|