Write a program to Transpose an array of 4*4

/*
PROGRAM:
——–
Write a program to Transpose an array of 4*4.
*/

#include<stdio.h>
#include<conio.h>

void main()
{
int a[4][4],t[4][4],i,j;
clrscr();

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf(“Enter value for Row-%d & Column-%d: “,i+1,j+1);
scanf(“%d”,&a[i][j]);
}
printf(“\n”);
}

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
t[j][i]=a[i][j];
}
}
printf(“\n\nTransposed Matrix is: \n\n”);
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf(“%4d”,t[i][j]);
}
printf(“\n”);
}
getch();
}
/*
OUTPUT:
——-
Enter value for Row-1 & Column-1: 1
Enter value for Row-1 & Column-2: 2
Enter value for Row-1 & Column-3: 3
Enter value for Row-1 & Column-4: 4

Enter value for Row-2 & Column-1: 5
Enter value for Row-2 & Column-2: 6
Enter value for Row-2 & Column-3: 7
Enter value for Row-2 & Column-4: 8

Enter value for Row-3 & Column-1: 9
Enter value for Row-3 & Column-2: 0
Enter value for Row-3 & Column-3: 1
Enter value for Row-3 & Column-4: 2

Enter value for Row-4 & Column-1: 5
Enter value for Row-4 & Column-2: 6
Enter value for Row-4 & Column-3: 7
Enter value for Row-4 & Column-4: 8

Transposed Matrix is:

1 5 9 5
2 6 0 6
3 7 1 7
4 8 2 8
*/

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.