0% found this document useful (0 votes)
6 views1 page

Add Two Matrices in C Programming

Uploaded by

amritranabhat09
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Add Two Matrices in C Programming

Uploaded by

amritranabhat09
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//WAP which stores element of two matrices, add two matrices and display the sum

matrix in proper format.


#include <stdio.h>
int main() {
int i, j, m, n, a[5][5], b[5][5], s[5][5];
printf("Enter size of rows and columns: ");
scanf("%d%d", &m, &n);
printf("Enter the elements of the first matrix:\n");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &a[i][j]);
}
}
printf("Enter the elements of the second matrix:\n");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &b[i][j]);
}
}
printf("The sum of the two matrices is:\n");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
s[i][j]=a[i]+b[j];
printf("%d\t", s[i][j]);

}
printf("\n");
}
return 0;
}

You might also like