Skip to main content

Matrix program or 2D Array in C language Transpose of Matrix program in C language

 Matrix program or 2D Array in C language 

In C language ,A two dimensional array is also known as matrix .Today we will learn about Matrix  .We all know that we also use loop to define an array .We will create a matrix program using a nested for loop.

1.Matrix program in C language:




Output are:

ENTER THE ROW AND COL:2
3
ENTER THE MATRIX ELEMENTS:ENTER a[0][0] : 2
ENTER a[0][1] : 5
ENTER a[0][2] : 7
ENTER a[1][0] : 8
ENTER a[1][1] : 6
ENTER a[1][2] : 1
MATRIX ARE:
2       5       7
8       6       1


2.Transpose of matrix in C language:
        
            Matrix  a
a[0][0]= 4,   a[0][1]=1,   a[0][2]=8:
a[1][0]= 9,   a[1][1]=0,   a[1][2]=5:
a[2][0]= 7,   a[2][1]=3,   a[2][2]=2:

            Transpose of Matrix 
                                       

a[0][0]=4, a[1][0]=9, a[2][0]=7:
a[0][1]=1, a[1][1]=0, a[2][1]=3:
a[0][2]=8, a[1][2]=5, a[2][2]=2:

Here the index of the row in the matrix a is being exchanged with the index of the column.


PROGRAM ARE:


In C language

OUTPUT ARE:


Enter the matrix row & col:3
2
Enter A[0][0] =4
Enter A[0][1] =5
Enter A[1][0] =6
Enter A[1][1] =1
Enter A[2][0] =2
Enter A[2][1] =3
Matrix are:
4       5
6       1
2       3
Transpose of matrix are:
4       6       2
5       1       3






Comments

Popular posts from this blog

Two dimensional array in C language or matrix program in c language

 Two dimensional arrays: 1.Two dimensional array is known as matrix. 2.An array with two subscripts is termed as two-dimensional array. 3.We know that a one dimensional array can store a row of elements, so a two-dimensional array enables us to store multiple roes of elements. The syntax of declaring a two-dimensional array is : Data-type array name[row][column]; For reading value : for(k=0;k<4;k++) { for(l=0;l<3;l++) { scanf("%d",&a[k][l]); } } For displaying value : for(k=0;k<4;k++) { for(l=0;l<3;l++) { printf("%d",a[k][l]); } printf("\n"); } Simple Matrix Program : #include"stdio.h" int main() { int a[3][3]; int k,l; printf("Enter the array elements: \n"); for(k=0;k<3;k++)  //for reading value// { for(l=0;l<3;l++) { printf("Enter a[%d][%d] :",k,l); scanf("%d",&a[k][l]); } } printf("\n\nMatrix are: \n"); for(k=0;k<3;k++)  //for displaying value...

One dimensional array declaration in c language basic of array

One D array **Definition of array** Array can be define as a collection of data object which are stored in consecutive memory location with a common variable name.                                                                                                        or  Array is the collection of similar data types or collection of similar entity stored in contiguous memory location . **Initialization of array** Array can be made initialization at the time of declaration itself. The general form of array initialization is as below  1.Data type array name[size] 2. Data type array name[size]={element1,element2,element3,.....} Example: int a[[4]={1,5,8,4} char d[3]={'A','R',u...