Q. Write a program using pointer, to find transpose of a given matrix.
#BIT_2017_2b_5Marks_Solution
==> code goes like this:
#include<stdio.h>
int main()
{
int a[10][10],b[10][10];
int i,j,rows,cols;
printf("Enter size of matrix: ");
scanf("%d %d",&rows,&cols);
//For Input
printf("Enter elements :");
for(i=0;i<rows;i++)
{
for ( j = 0; j < cols; j++)
{
scanf("%d",(*(a+i)+j));
}
}
//For Transpose
for ( i = 0; i < rows; i++)
{
for ( j = 0; j < cols; j++)
{
*(*(b+j)+i)=*(*(a+i)+j);
printf("%d \t",*(*(b+i)+j));
}
}
//For Displaying Transpose
for ( i = 0; i < rows; i++)
{
for ( j = 0; j < cols; j++)
{
printf("%d \t",*(*(b+i)+j));
}
printf("\n");
}
return 0;
}
Output:
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Home / C Programs /
OldQuestionSolution2017C /
Transpose of matrix using pointer in c
/ Transpose of a given matrix using pointer - C
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment