C Program to Add Two Matrices
#include<stdio.h> #include<conio.h> void main() { int a[15][15],b[15][15],c[15][15],k,n,i,j; clrscr(); printf("How many rows and columns you want to give ?"); scanf("%d%d",&k,&n); printf("Enter the value of A matrix :"); for(i=0;i<k;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf("Enter the value of B matrix :"); for(i=0;i<k;i++) for(j=0;j<n;j++) scanf("%d",&b[i][j]); for(i=0;i<k;i++) for(j=0;j<n;j++) c[i][j]=a[i][j]+b[i][j]; printf("The Addition of Matrix :"); for(i=0;i<k;i++) { for(j=0;j<n;j++) printf("%5d",c[i][j]); printf("\n"); } getch(); }
Output: