To Add Two matrices Using Arrays
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q;
printf(" Enter row and column of Matrix A : \n");
scanf("%d%d",&m,&n);
printf("\n enter row and column of Matrix B: \n");
scanf("%d%d",&p,&q);
if ( m==p && n==q)
{
printf ("The Two matrices can be added.\n Enter the elements of A>>");
for ( i=0; i<m;i++)
for (j=0;j<n;j++)
scanf("%d", &a[i][j]);
printf ("Enter The Elements of matrix B:\n");
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 (" A + B = \n");
for (i =0; i<m;i++)
{
for (j=0;j<n;j++)
printf("%5d\n",c[i][j]);
}
}
else printf(" Matrices cannot be added.");
getch();
}
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q;
printf(" Enter row and column of Matrix A : \n");
scanf("%d%d",&m,&n);
printf("\n enter row and column of Matrix B: \n");
scanf("%d%d",&p,&q);
if ( m==p && n==q)
{
printf ("The Two matrices can be added.\n Enter the elements of A>>");
for ( i=0; i<m;i++)
for (j=0;j<n;j++)
scanf("%d", &a[i][j]);
printf ("Enter The Elements of matrix B:\n");
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 (" A + B = \n");
for (i =0; i<m;i++)
{
for (j=0;j<n;j++)
printf("%5d\n",c[i][j]);
}
}
else printf(" Matrices cannot be added.");
getch();
}
No comments:
Post a Comment