10 Jan 2015

PROGRAM FOR ADDING TWO MATRIX



#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],b[10][10],c1[10][10],r,c,m,n,i,j;
printf("enter the row and column value of a\n");
scanf("%d%d",&r,&c);
printf("enter the element into a\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the row and column of b\n");
scanf("%d%d",&m,&n);
printf("enter element into b\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
if ((r==m)&&(c==n))
{
  for(i=0;i<r;i++)
  {
   for(j=0;j<c;j++)
    {
     c1[i][j]=a[i][j]+b[i][j];
    }
  }

  printf("the result is\n");
   for(i=0;i<r;i++)
    {
     for(j=0;j<c;j++)
      {
       printf("%d\t",c1[i][j]);
      }
     printf("\n");
   }
}

else
printf("addition is not possible\n");
getch();
}

No comments:

Post a Comment