Matrix is collection of number or data in square bracket and matrix which covert number of elements in row to number of elements in column is called transpose of matrix.
For example:
Now
you understand the concept of transpose of matrix. So now let’s talk about what should you know before write this program.
Before
write a program you should know about:
- Assign operator
- Array (In this program we use 2-D array)
- Loop
- Nested-loop
So
now we write our program to find the transpose of given matrix :
SOURCE
CODE:
#include<stdio.h>int main(){ printf("enter matrix A to get transpose of matrix :\n"); int a[30][30],i,j,row,col,result[30][30]; printf("enter no. of row :"); scanf("%d",&row); printf("enter no. of column :"); scanf("%d",&col); printf("\nenter matrix A to get transpose of matrix :\n"); for(i=0;i<row;i++){ for(j=0;j<col;j++){ scanf("%d",&a[i][j]); } } printf("\nmatrix A : \n\n"); for(i=0;i<row;i++){ for(j=0;j<col;j++){ printf("%d\t",a[i][j]); } printf("\n"); } for(i=0;i<row;i++){ for(j=0;j<col;j++){ result[j][i]=a[i][j]; } } printf("\ntranspose of matrix A is :\n\n"); for(i=0;i<col;i++){ for(j=0;j<row;j++){ printf("%d\t",result[i][j]); } printf("\n"); } return 0;}
OUTPUT:
enter matrix A to get transpose of matrix :
enter no. of row :3
enter no. of column :3
enter matrix A to get transpose of matrix :
1
2
3
4
5
6
7
8
9
matrix A :
1 2 3
4 5 6
7 8 9
transpose of matrix A is :
1 4 7
2 5 8
3 6 9
ANOTHER OUTPUT:
enter matrix A to get transpose of matrix : enter no. of row :3 enter no. of colomn :2 enter matrix A to get transpose of matrix : 1 2 3 4 5 6 matrix A : 1 2 3 4 5 6 transpose of matrix A is : 1 3 5 2 4 6
Basic
think used in this program:
Arithmetic
operator: addition, subtraction,
multiplication, division etc. are the arithmetic operators. In this program arithmetic
operator is not use (this is only for understanding).
Assign
operator: basic meaning
of assign operator is equality (=, +=).
Array: array is used to store multiple constants in
single variable. There are three type of array and they are:
- 1-Dimensional array
- 2-Dimensional array and
- Multiple Dimensional array
Loop:
basically loop is used to run
one statement or one condition multiple times. Loop run until condition is true
after condition is false loop will not execute. There are three types of loop.
- While loop
- Do-while loop
- For loop
In
this program 'for' loop is used.
Nested
loop: if loop inside
another loop then it’s called nesting of loop.
0 Comments