#include<stdio.h>
void read(int a[50][50],int r,int c);
void display(int a[50][50],int r,int c);
void transpose(int a[50][50],int r,int c);
int main()
{
int a[50][50],r,c,Sum;
printf("Enter the row size of the matrix\n");
scanf("%d",&r);
printf("Enter the column size of the matrix\n");
scanf("%d",&c);
printf("Enter the matrix elements\n");
read(a,r,c);
printf("The matrix is:\n");
display(a,r,c);
transpose(a,r,c);
}
void read(int a[50][50],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
}
void display(int a[50][50],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
}
}
printf("\n");
}
void transpose(int a[50][50],int r,int c)
{
int i,j,b[50][50];
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
b[j][i]=a[i][j];
}
}
printf("transposed matrix is :\n");
display(b,r,c);
}
Output:
void read(int a[50][50],int r,int c);
void display(int a[50][50],int r,int c);
void transpose(int a[50][50],int r,int c);
int main()
{
int a[50][50],r,c,Sum;
printf("Enter the row size of the matrix\n");
scanf("%d",&r);
printf("Enter the column size of the matrix\n");
scanf("%d",&c);
printf("Enter the matrix elements\n");
read(a,r,c);
printf("The matrix is:\n");
display(a,r,c);
transpose(a,r,c);
}
void read(int a[50][50],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
}
void display(int a[50][50],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
}
}
printf("\n");
}
void transpose(int a[50][50],int r,int c)
{
int i,j,b[50][50];
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
b[j][i]=a[i][j];
}
}
printf("transposed matrix is :\n");
display(b,r,c);
}
Output:
Comments
Post a Comment