WRITE A PROGRAM TO SUM OF TWO MATRICES - Code

Latest

programs

Sunday, October 30, 2011

WRITE A PROGRAM TO SUM OF TWO MATRICES



WRITE A PROGRAM TO SUM OF TWO MATRICES

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int i,j,k,r1,r2,c1,c2;
clrscr();
printf("input the order of matrix A:");
scanf("%d%d",&r1,&c1);
printf("input the order of matrix B:");
scanf("%d%d",&r2,&c2);
printf("enter the element of matrix A(row wise) \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}}
printf("enter the element of matrix B(row wise) \n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}}
 printf("the element of matrix A is \n");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c1;j++)
{
printf("%d",a[i][j]);
printf("\t");
}}

printf("the element of matrix B is \n");
for(i=0;i<r2;i++)
{
printf("\n");
for(j=0;j<c2;j++)
{
printf("%d",b[i][j]);
printf("\t");
}}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}}
printf("the addition of matrix is :");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c2;j++)
{
printf("%d",c[i][j]);
printf("\t");
}}
getch();
}






1 comment: