C program to find transpose of matrix using for loop while

itstudentjunction


C program to find transpose of matrix using for loop while


what is transpose of a matrix?

A transpose of a given matrix is a matrix obtained by changing elements of rows to colums and columns to rows

eg :

1 3 5 1
2 1 6 1
5 3 2 9

The transpose of above matix is

1 2 5
3 1 3
5 6 2
1 1 9




write a C program to find transpose of a matrix using for loop


write a C program to find transpose of a matrix using for loop / WAP to find transpose of matrix

#include<stdio.h>
#include<conio.h>
int main()
{
int m, n, i, j;
int c[10][10], transpose[10][10]; // c[][] is original matrix
printf("To find for transpose of a given matrix ");
printf("Enter the number of rows and columns of matrix ");
scanf("%d%d",&m,&n);
printf("Enter the elements of matrix \n");
for( i = 0 ; i < m ; i++ )
{
for( j = 0 ; j < n ; j++ )
{
scanf("%d",&c[i][j]);
}
} for( i = 0 ; i < m ; i++ )
{
for( j = 0 ; j < n ; j++ )
{
transpose[j][i] = c [i][j];
}
}
printf("Transpose of matrix is:-\n");
for( i = 0 ; i < n ; i++ )
{
for( j = 0 ; j < m ; j++ )
{
printf("%d\t",transpose[i][j]);
}
printf("\n");
}
getch();
return 0;
}

OUTPUT:

To find transpose of a given matrix

Enter the number of rows and columns of matrix 2 2

Enter the elements of matrix 0 2 3 4

Transpose of matrix is:

0 3
2 4

WAP for transpose of a matrix using while loop


write a C program to print transpose of a matrix using while loop / write a C program for transpose of a matrix

#include<stdio.h>
#include<conio.h>
int main()
{
int m, n, i=0, j=0;
int c[10][10], transpose[10][10];
printf("To print transpose of a given matrix ");
printf("Enter no. of rows and columns of matrix ");
scanf("%d%d",&m,&n);
printf("Enter elements into matrix \n");
while(i<m)
{
while(j<n)
{
scanf("%d",&c[i][j]);
transpose[j][i] = c [i][j];
j++ ;
}
i++;
}
printf("Transpose of matrix is :\n");
i=0;
j=0;
while(i<m)
{
while(j<n)
{
printf("%d\t",transpose[i][j]);
j++ ;
}
printf("\n");
i++;
}
}

OUTPUT:

To print transpose of a given matrix

Enter no. of rows and columns of matrix 2 2

Enter elements into matrix 0 1 1 0

Transpose of matrix is:

0 1
1 0

list of c programs



Most popular programs

write a program to find factorial using c
WAP to Calculate Simple Interest
Check for even / odd
perfect or not
sum of two matrices
display numbers pyramid
show amicable pairs
find factors print prime factors using C
convert to uppercase
prime numbers using for loop
write a program to implement pascal Triangle
check reverse string arrays
find string length strlen
Calculate compound Interest
check armstrong or not
print prime numbers using while
solve towers of hanoi
Display Floyd’s Triangle
reverse string using pointers
write a program to find a number is prime or not
Show revers number
calculate LCM concatinate strings using arrays
write a program to find palindrome or not
WAP to print sum of Digits
write a C program to find transpose of a matrix using for loop
show lower triangle
multipiy two matrices
write a program to calculate GCD
strong number or not
check substring in c
string length using arrays
string length using pointers
convert to lowercase
WAP to find factors
count no.of digits
show inverse of matrix
show reverse string strrev
write a program to display upper triangle
write a C program for transpose of a matrix
concatinate strings strCat
convert to lowercase
check for palindrome string
print substring position
compare two strings arrays
compare strings strcmp
find roots of quadriaic expression
show fibonacci numbers
factorial using recurrsion
sum of factorial series
convert decimal to binary
armstrong numbers

write a C program to print transpose of a matrix using while loop

decimal to octal
compare strings pointers
decimal to hexadecimal
sum of n numbers
average of n
largest of two
largest of n

strong numbers
perfect numbers using for loop



C Programs Data structures Programs in c Data structures Programs in c++ Unix commands Linux commands C++ programs Data structures Algorithms Java Programs UML Diagrams Assembly Language Programs DBMS j2ee programming