Sunday, 5 January 2014

ADDITION OF TWO MATRIX IN C

ADDITION OF TWO MATRIX

Here we write code for Addition of Two Matrix in C

#include<stdio.h>
#include<conio.h>
void main()
{
int x[3][3],y[3][3],z[3][3],i,j;
clrscr();
printf("ENTER ELEMENTS OF 1st MATRIX\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&x[i][j]);
}
printf("ENTER ELEMENTS OF 2nd MATRIX\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&y[i][j]);
}
printf("MATRIX [X]");
for(i=0;i<3;i++)
{
printf("\n\n");
for(j=0;j<3;j++)
printf(" %d",x[i][j]);
}
printf("\nMATRIX [Y]");
for(i=0;i<3;i++)
{
printf("\n\n");
for(j=0;j<3;j++)
printf(" %d",y[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
z[i][j]=x[i][j]+y[i][j];
}
printf("\nMATRIX [Z]");
for(i=0;i<3;i++)
{
printf("\n\n");
for(j=0;j<3;j++)
printf(" %d",z[i][j]);
}
getch();
}


Output

ADDITION OF TWO MATRIX IN C

No comments:

Post a Comment