Input number in two different matrix and print sum of those matrices.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n1[3][3], n2[3][3], n3[3][3], i, j;
clrscr ( );
printf ("\n\t\t\t Enter numbers in first matrix\n");
printf("\n\t\t\t________________________________________\n");
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++)
{
printf("\n\t\t\t Position [%d] [%d]..:",i, j); scanf ("%d", &n1[i][ j] );
}
}
clrscr ( );
printf ("\n\t\t\t Enter numbers in second matrix\n");
printf("\n\t\t\t________________________________________\n");
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++)
{
printf("\n\t\t\t Position [%d] [%d]..:",i,j); scanf ("%d", &n2[i][ j] );
}
}
clrscr ( );
printf("\n\n\n\n\t\t\t\t1st Matrix\n\t\t\t____________________________\n\n\t\t\t\t");
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++ )
{
printf ("%3d ", n1[i][ j] );
}
printf ("\n\t\t\t\t");
}
printf("\n\n\t\t\t\t2nd Matrix\n\t\t\t____________________________\n\n\t\t\t\t");
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++ )
{
printf ("%3d ", n2[i][ j] );
}
printf ("\n\t\t\t\t");
}
printf("\n\n\t\t\t\t Added Matrix\n\t\t\t____________________________\n\n\t\t\t\t");
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++ )
{
n3[i][ j] = n1[i][ j] + n2[i][ j];
printf ("%3d ", n3[i][ j] );
}
printf ("\n\t\t\t\t");
}
getch ( );
}
Click here to contact us
No comments:
Post a Comment