Tuesday 1 October 2013

C PROGRAM TO ADD TWO MATRICES

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],i,j,m,n,p,q,c[10][10];
clrscr();
printf("\n enter the no of rows and columns of first matrix");
scanf("%d%d",&m,&n);
printf("\n enter the no of rows and columns of second matrix");
scanf("%d%d",&p,&q);
if((m==p)&&(n==q));
{
printf("\n enter the elements of first matrix");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\n enter the elements of second matrix");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
printf("\n sum of matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d ",c[i][j]);
printf("\n");
}
getch();
exit(0);
}
printf("\n matrix addition not posible");
}

No comments:

Post a Comment