c program to addition of two matrices.

Programming Example

Write a C program to input two matrix of size 3x3 and add two matrices in another 3rd matrix and print it.

Solution

#include<stdio.h>
int main()
{
	int matrix1[3][3],matrix2[3][3],matrix3[3][3],a,b,c;
	
	printf("Enter 9 Elments for Matrix 1 : ");
	for(a=0;a<3;a++)
	{	
		for(b=0;b<3;b++)
		{
			scanf("%d",&matrix1[a][b]);
		}
	}
	printf("Enter 9 Elments for Matrix 2 : ");
	for(a=0;a<3;a++)
	{	
		for(b=0;b<3;b++)
		{
			scanf("%d",&matrix2[a][b]);
		}
	}
	for(a=0;a<3;a++)
	{	
		for(b=0;b<3;b++)
		{		
			matrix3[a][b]=matrix1[a][b]+matrix2[a][b];			
		}
	}
	printf("Matrix 1 : \n");
	for(a=0;a<3;a++)
	{	
		for(b=0;b<3;b++)
		{
			printf("%d  ",matrix1[a][b]);
		}
		printf("\n");
	}
	printf("\nMatrix 2 : \n");
	for(a=0;a<3;a++)
	{	
		for(b=0;b<3;b++)
		{
			printf("%d  ",matrix2[a][b]);
		}
		printf("\n");
	}
	printf("\nMultiplication of 2 Matrix (Matrix 3) : \n");
	for(a=0;a<3;a++)
	{	
		for(b=0;b<3;b++)
		{
			printf("%d  ",matrix3[a][b]);
		}
		printf("\n");
	}
	return 0;
}
Output

Enter 9 Elments for Matrix 1 :

1 2 3

3 4 5

2 3 4

Enter 9 Elments for Matrix 2 :

4 5 3

2 3 3

2 3 4

Matrix 1 :

1  2  3

3  4  5

2  3  4


Matrix 2 :

4  5  3

2  3  3

2  3  4


Multiplication of 2 Matrix (Matrix 3) :

5  7  6

5  7  8

4  6  8

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad