#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main() {
srand(time(NULL));
const int N = 4;
int arr[N][N];
int i = 0;
int j = 0;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
arr[i][j] = rand() % 100;
printf("Original matrix:\n");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++)
printf("%d ", arr[i][j]);
printf("\n");
}
for(i = 0;i<N;i++)
for (j = i + 1; j < N; j++) {
int temp = arr[i][j];
arr[i][j] = arr[j][i];
arr[j][i] = temp;
}
printf("\nTranspose matrix:\n");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++)
printf("%d ", arr[i][j]);
printf("\n");
}
return 0;
}
Comments
Leave a comment