Input two matrices and print the multiplication of those matrices.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n1[3][3], n2[3][3], n3[3][3], i, j, k, m = 0;
clrscr( );
printf ("\n\t\t\t Enter numbers in first matrix");
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");
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\t 1st Matrix\n\t\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\t 2nd Matrix\n\t\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");
}
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++ )
{
m = 0;
for ( k = 0; k < 3; k++ )
{
m = m + n1[i][k] * n2[k][ j];
}
n3[i][ j] = m;
}
}
printf("\n\n\t\t\t\t Multiplied Matrix\n\t\t\t\t___________________\n\n\t\t\t\t");
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++ )
{
printf("%d\t",n3[i][j]);
}
printf("\n\t\t\t\t");
}
getch();
}
Click here to contact us
No comments:
Post a Comment