MATRIX
ADDITION
#include<stdio.h>
#include<conio.h>
void main()
{int
a[5][5],b[5][5],c[5][5],I,j,n,m,p,q;
Clrscr();
Printf(“enter the rows and columns of
the first matrix”);
Scanf(“%d%d”,&m,&n);
Printf(“enter the first matrix”);
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
{scanf(“%d”,&a[i][j]);
}
}
Printf(“enter the rows and columns of
the second matrix”);
Scanf(“%d%d”,&p,&q);
Printf(“enter the second matrix”);
for(i=0;i<p;i++)
{for(j=0;j<q;j++)
{scanf(%d”,&b[i][j]);
}
}
If(m!=p||n!q)
Printf(“addition is not possible”);
Printf(”\n the entered matrices
are:\n”);
else
{for(i=0;i<m;i++)
{for(j=0;j <n;j++)
{printf(“%d”,a[i][j]);
}
Printf(“\n”);
}
Printf(“\n\n”);
for(i=0;i<p;i++)
{for(j=0;j<q;j++)
{
Printf(“%d”b[i][j]);
}
Printf(“\n”);
}
Printf(“\n sum is”);
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
{c[i][j]=a[i][j]+b[i][j];
Printf(“%d”,c[i][j]);
}
Printf(“\n”);
}
}
getch();
}
OUTPUT
Enter the rows and columns of the
first matrix
2
3
Enter the first matrix
2
2 2 2
2 2
Enter the rows and colums of the
second matrix
2
3
Enter the second matrix
3 3 3 3 3 3
The entered matrices are:
2
2 2
2
2 2
3
3 3
3
3 3
Sum is:
5
5 5
5
5 5






0 comments:
Post a Comment