Thursday, April 3, 2014

//PROGRAM TO ADD TWO MATRICES

//PROGRAM TO ADD TWO MATRICES
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,r1,c1,r2,c2;
clrscr();

printf("enetr the no of rows of first matrics\n");
scanf("%d",&r1);
printf("enter the no of cols of first matrics\n");
scanf("%d",&c1);
printf("enetr the no of rows of second matrics\n");
scanf("%d",&r2);
printf("enter the no of cols of second matrics\n");
scanf("%d",&c2);

printf("enter the elements of first matrics\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
}

printf("the elements of first matrics are \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf(" %d ",a[i][j]);
printf("\n\n");
}

printf("enter the elements of second matrics\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&b[i][j]);
}

printf("the elements of second matrics are \n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf(" %d ",b[i][j]);
printf("\n\n");
}

if(r1==r2&&c1==c2)
{
printf("the addition of two matrices is\n");
for(i=0;i<r1;i++)
{
  for(j=0;j<c1;j++)
    {
     c[i][j]=a[i][j]+b[i][j];
    }
 printf(" %d ",C[i][j]);}
}
else
printf("addition is not possible\n");
getch();
}

No comments:

Post a Comment