/* PROGRAM TO ADD TWO MATRICES*/
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,m,n;
int a[5][5],b[5][5],c[10][10];
clrscr();
printf("Enter size of 2D arrays:");
scanf("%d %d",&m,&n);
printf("Enter elements of 1st 2d matrix:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
printf("\na[%d][%d]=", i,j);
scanf("%d", &a[i][j]);
}
printf("Enter elements of 2nd 2D matrix:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
printf("\nb[%d][%d]=", i,j);
scanf("%d", &b[i][j]);
}
printf("\nThe sum of two matrix has these elements:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
c[i][j]=a[i][j]+b[i][j];
printf("\nc[%d][%d]=%d", i,j,c[i][j]);
}
getch();
}
/* OUTPUT:-
Enter size of 2D arrays:1
2
Enter elements of 1st 2d matrix:
a[1][1]=1
a[1][2]=2
Enter elements of 2nd 2D matrix:
b[1][1]=1
b[1][2]=5
The sum of two matrix has these elements:
c[1][1]=2
c[1][2]=7 */
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,m,n;
int a[5][5],b[5][5],c[10][10];
clrscr();
printf("Enter size of 2D arrays:");
scanf("%d %d",&m,&n);
printf("Enter elements of 1st 2d matrix:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
printf("\na[%d][%d]=", i,j);
scanf("%d", &a[i][j]);
}
printf("Enter elements of 2nd 2D matrix:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
printf("\nb[%d][%d]=", i,j);
scanf("%d", &b[i][j]);
}
printf("\nThe sum of two matrix has these elements:");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
c[i][j]=a[i][j]+b[i][j];
printf("\nc[%d][%d]=%d", i,j,c[i][j]);
}
getch();
}
/* OUTPUT:-
Enter size of 2D arrays:1
2
Enter elements of 1st 2d matrix:
a[1][1]=1
a[1][2]=2
Enter elements of 2nd 2D matrix:
b[1][1]=1
b[1][2]=5
The sum of two matrix has these elements:
c[1][1]=2
c[1][2]=7 */
No comments:
Post a Comment