Skip to main content

Matrix Addition and subtraction program in C language

 Matrix Addition and Subtraction program in C language

Today here you will be able to learn about multiple tasks in Matrix-like addition, subtraction, and multiplication.

@#1.Matrix Addition  

Suppose that we have two matrices of 3X3 orders. This matrix A and B. In this program  




C is the addition of A & B; i and k are used for initialization.

Matrix Addition Program 



Output is: 

Enter The Matrix row & col = 2
3
Enter the First matrix :
Enter matrix[0][0]=2
Enter matrix[0][1]=1
Enter matrix[0][2]=3
Enter matrix[1][0]=6
Enter matrix[1][1]=54
Enter matrix[1][2]=7
First matrix are:
2       1       3
6       54      7
Enter the Second matrix :
Enter matrix[0][0]=8
Enter matrix[0][1]=9
Enter matrix[0][2]=6
Enter matrix[1][0]=4
Enter matrix[1][1]=1
Enter matrix[1][2]=3
Second matrix are:
8       9       6
4       1       3
Matrix sum are:
10      10      9
10      55      10


@#2.Matrix Subtraction

    Two matrices a & b.






Matrix Subtraction program 



Output is: 

Enter matrix[0][1]=4
Enter matrix[1][0]=8
Enter matrix[1][1]=5
Enter matrix[2][0]=9
Enter matrix[2][1]=7
First matrix are:
4       4
8       5
9       7
Enter the Second matrix :
Enter matrix[0][0]=1
Enter matrix[0][1]=0
Enter matrix[1][0]=2
Enter matrix[1][1]=3
Enter matrix[2][0]=03
Enter matrix[2][1]=12
Second matrix are:
1       0
2       3
3       12
Matrix sub are:
3       4
6       2
6       -5







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...

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: /*MATRIX PROGRAM*/ #include"stdio.h" int main() { int a[10][10]; int r,c,k,l; printf("ENTER THE ROW AND COL:"); scanf("%d %d",&r,&c); printf("ENTER THE MATRIX ELEMENTS:"); for(k=0;k 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:...