Sun Jun 10 2018
Matrix Addition
C Programming1011 views
File Name: matrix-addition.c
#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:
10 10 10
10 10 10
10 10 10
Reference:
Author:Geekboots