//WAP to multiplication of two 2x2 matrix. #include <stdio.h> #include <conio.h> void main() { int i,j,k,a[2][2],b[2][2],c[2][2],sum; clrscr(); printf( "Enter any element of 1st matrix:\n" ); for (i=0;i<2;i++) { for (j=0;j<2;j++) scanf( "%d" ,&a[i][j]); } printf( "Entre any element of 2nd matrix:\n" ); for (i=0;i<2;i++) { for (j=0;j<2;j++) scanf( "%d" ,&b[i][j]); } //Multiplication logic for (i=0;i<2;i++) { sum=0; for (k=0;k<2;k++) { sum = sum + a[i][k] * b[i][j]; c[i][j]=sum; } } printf( "Result matrix:" ); for (i=0;i<2;i++) { for (j=0;j<2;j++) printf( "%d\t" ,c[i][j]); printf( "\n" ); } getch(); }
Take Pure Information, Always Original Content