C Programming

Matrix Addition

Learn C programming for calculate sum of two matrix and store in another two dimensional array

6/10/2018
0 views
matrix-addition.cC
#include<stdio.h>

int main() {

	/* Declaration of two dimensional array */
	int a[3][3], b[3][3], c[3][3], i, j;
	printf("Enter value for 1st matrix:\n");
	for(i = 0; i < 3; i++)
		for(j = 0; j < 3; j++)
			scanf("%d", &a[i][j]);
	printf("Enter value for 2nd matrix:\n");
	for(i = 0; i < 3; i++)
		for(j = 0; j < 3; j++)
			scanf("%d", &b[i][j]);

	/* Adding two matrix */
	for(i = 0; i < 3; i++)
		for(j = 0; j < 3; j++)
			c[i][j] = a[i][j] + b[i][j];
	printf("After addition of two 3x3 matrix:\n");
	for(i = 0; i < 3; i++) {
		for(j = 0; j < 3; j++)
			printf("%d\t",c[i][j]);
		printf("\n");
	}
	return 0;
}



/* Output */
Enter value for 1st matrix:
1
2
3
4
5
6
7
8
9

Enter value for 2nd matrix:
9
8
7
6
5
4
3
2
1

After addition of two 3x3 matrix:
101010
101010
101010
C programmingsum of two matrixmatrix addition

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com