Transpose of a 3x3 Matrix in C
Problem: Write a C program to find the transpose of a 3x3 matrix.
🔍 Explanation:
- The transpose flips the matrix over its diagonal.
- Each element at position
[i][j]
in transpose is taken from[j][i]
of original.
✅ C Program:
#include <stdio.h>
int main() {
int matrix[3][3], transpose[3][3];
printf("Enter 9 elements of 3x3 matrix:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
scanf("%d", &matrix[i][j]);
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
transpose[i][j] = matrix[j][i];
}
}
printf("Transpose of the matrix:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", transpose[i][j]);
}
printf("\n");
}
return 0;
}
📤 Sample Output:
Transpose of the matrix: 1 4 7 2 5 8 3 6 9
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন