C program to print subtract of two matrices of order 3X3

Matrix: A matrix is a collection of numbers arranged into a fixed number of rows

               and columns.

 

Let’s write a program which print subtract of two matrices.

 

Step 1: Let’s open Turbo C and write the following code.

 

// Code

 

//Add preprocessor file

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,a[10][10],b[10][10],c[10][10];

 

// clear screen;

clrscr();

printf(“enter elements of first matrix: ”);

for(i=0;i<3;i++)

{

for{j=0;j<3;j++)

{

scanf(“%d”,&a[i][j]);

}

}

printf(“enter elements of second matrx:”);

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

scanf(“%d”,&b[i][j]);

}

}

printf(“the first matrix is:\n”);

for(i=0;i<3;i++)

{

printf(“\n”);

{

for(j=0;j<3;j++)

printf(“%d\t”,a[i][j]);

}

}

printf(“the second matrix is:\n”);

for(i=0;i<3;i++)

{
printf(“\n”);

{

for(j=0;j<3;j++)
printf(“%d\t”,b[i][j]);

}

}

for(i=0;i<3;i++)

{

for(i=0;i<3;i++)

{

c[i][j]=a[i][j]-b[i][j];

}

}

printf(“\n subtraction of matrices is: \n”);

for(i=0;i<3;i++)

{

for(j=o;j<3;j++)

{

 

// Print the Result

printf(“%d\t”,c[i][j]);

}

}

printf(“\n”);

}

getch();

}

 

Step 2: Save it and name it MATRIXSUBTRACT.CPP.

 

 

Step 3:Compile it to check errors by pressing ALT+F9.

 

 

Step 4: Now run the program and see output.

 

Output:

 

output.OUTPUT

Happy coding.

 

 

 

 

Tags: , , ,

  • Nice program. This is a very good program for new programmers to understand concept of 2 dimensional array and for loops.
    The subtraction of two matrices M × N matrices A and B, denoted by A – B, is again an M × N matrix computed by subtracting corresponding elements.