Program to add two matrices of order 3X3 in C

 

Let’s write the following code to find sum of two matrices

 

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

 

Code:

 

 

//Add preprocessor

 

#include<stdio.h>

#include<conio.h>

void main()

{

 

//Declaring variables

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

 

//Clear screen

clrscr();

 

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

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

{

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

{

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

}

}

       printf(“enter all elements of second matrix : \n”);

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

{

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

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

}

}

        printf(“sum of matrices are: \n”);

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

{

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

{

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

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

}

       printf(“\n”);

}

        getch();

}

 

 

Step 2 : Now save it by pressing F2 and name it MATRIX.CPP.

 

 

 

 

Step 3: Now compile it by pressing ALT+F9 to check errors in program and correct them.

 

 

 

 

Step 4: Run the program by pressing ALT +R or click on RUN and see output.

 

 

 

 

Output:

 

output matrix

 

 

I hope this article was helpful.

 

 

HAPPY CODING.

 

 

 

 

 

Tags: , , , ,