1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 52 | #include<stdio.h>
void read(int,int,int [][20]);
void add(int,int,int [][20],int [][20],int [][20]);
void display(int,int,int [][20]);
void main()
{
int r,c,mat[20][20],sem[20][20],sum[20][20];
printf("Enter the Value of Row and Column:- \n");
scanf("%d %d",&r, &c);
printf("Enter the First Matrix:- \n");
read(r,c,mat);
printf("Enter the Second Matrix:- \n");
read(r,c,sem);
add(r,c,mat,sem,sum);
printf("The Sum matrix is:- \n");
display(r,c,sum);
}
void read(int x,int y,int ma[20][20])
{
int i,j;
for (i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
scanf("%d",&ma[i][j]);
}
}
}
void add(int x, int y,int right[20][20],int left[20][20],int ans[20][20])
{
int i,j;
for (i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
ans[i][j]=right[i][j]+left[i][j];
}
}
}
void display(int x,int y, int ma[20][20])
{
int i,j;
for (i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
printf("%d\t",ma[i][j]);
}
printf("\n");
}
}
|
The Process is Quite simple in add function we pass 3 matrix so that can store the sum in one of the matrix and display it.
0 comments:
Post a Comment