Write a C program to Subtract Two Matrix

 TASK-

Write a C program to Subtract Two Matrix.

STEPS TO BE TAKEN:

1) Matrix is a type of array.
2) Array can have multiple dimension for example 1D,2D.
3) For getting inputs and giving outputs in 1D we use one loop, Same for when we have 2D we use 2 loops.
4) We will add two matrices using two loops.

CODE:

#include<stdio.h>
int main(){
int matA[3][3],matB[3][3],MatC[3][3];
int i,j;
//Getting values in matA
/*As stated Above we will use 2 for loops
 to operate Matrix as it is a 2D array;
*/
for (i=0;i<3;i++)//it works as rows
{
	for (j=0;j<3;j++)//it works as columns
	{
		printf("\nEnter [%d  %d] Entry of MatA: ",i+1,j+1);
		scanf("%d",&matA[i][j]);
	}
}
printf("\n\n");
//Getting Values in matB
for (i=0;i<3;i++)//it works as rows
{
	for (j=0;j<3;j++)//it works as columns
	{
		printf("\nEnter [%d  %d] Entry of MatB: ",i+1,j+1);
		scanf("%d",&matB[i][j]);
	}
}
//Time for sum
printf("\n\nHere is the Sum\n\n");
for (i=0;i<3;i++)
{
	for (j=0;j<3;j++)
	{
		MatC[i][j]=matA[i][j]-matB[i][j];
		printf("%d\t",MatC[i][j]);
	}
	printf("\n");
}
getchar();
return 0;
}

EXPECTED OUTPUT:





NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

2 Comments

  1. Really good, Kindly post Transpose program

    ReplyDelete
    Replies
    1. Already uploaded follow the link::
      https://let-us-c-the-program.blogspot.com/2022/01/write-c-program-to-find-transpose-of.html

      Delete
Post a Comment
Previous Post Next Post