/*Write a C program that uses functions to perform the
Calclulating transpose of a matrix in-place manner.*/
#include<stdio.h>
#include<conio.h>
void read_mat(int,int,int[10][10]);
void print_mat(int,int,int[10][10]);
void transpose_mat(int,int,int[10][10]);
main()
{
int a[10][10],b[10][10],i,j,m,n;
clrscr();
printf("Enter Matrix Row size and Column size:");
scanf("%d %d",&m,&n);
read_mat(m,n,a);
printf("Before Transpose:\n");
print_mat(m,n,a);
printf("After Transpose Matrix:\n");
transpose_mat(m,n,a);
getch();
}
void read_mat(int x,int y,int c[10][10])
{
int i,j;
printf("Enter Elements:");
for(i=0;i<x;i++)
for(j=0;j<y;j++)
scanf("%d",&c[i][j]);
}
void print_mat(int x,int y,int c[10][10])
{
int i,j;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
printf("%5d",c[i][j]);
printf("\n");
}
}
void transpose_mat(int x,int y,int a[10][10])
{
int i,j,b[10][10];
for(i=0;i<x;i++)
for(j=0;j<y;j++)
b[j][i]=a[i][j];
print_mat(x,y,b);
}
Calclulating transpose of a matrix in-place manner.*/
#include<stdio.h>
#include<conio.h>
void read_mat(int,int,int[10][10]);
void print_mat(int,int,int[10][10]);
void transpose_mat(int,int,int[10][10]);
main()
{
int a[10][10],b[10][10],i,j,m,n;
clrscr();
printf("Enter Matrix Row size and Column size:");
scanf("%d %d",&m,&n);
read_mat(m,n,a);
printf("Before Transpose:\n");
print_mat(m,n,a);
printf("After Transpose Matrix:\n");
transpose_mat(m,n,a);
getch();
}
void read_mat(int x,int y,int c[10][10])
{
int i,j;
printf("Enter Elements:");
for(i=0;i<x;i++)
for(j=0;j<y;j++)
scanf("%d",&c[i][j]);
}
void print_mat(int x,int y,int c[10][10])
{
int i,j;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
printf("%5d",c[i][j]);
printf("\n");
}
}
void transpose_mat(int x,int y,int a[10][10])
{
int i,j,b[10][10];
for(i=0;i<x;i++)
for(j=0;j<y;j++)
b[j][i]=a[i][j];
print_mat(x,y,b);
}
output:
Enter Matrix Row size and Column size:
3
3
Enter Elements:
3
Enter Elements:
1
2
3
4
5
6
7
8
9
Before Transpose:
1 2 3
4 5 6
7 8 9
After Transpose Matrix:
1 4 7
2 5 8
3 6 9
2
3
4
5
6
7
8
9
Before Transpose:
1 2 3
4 5 6
7 8 9
After Transpose Matrix:
1 4 7
2 5 8
3 6 9
0 comments:
Post a Comment