/*Product or Multiplication of two 2 * 2 matrix*/
#include<stdio.h>
#include<conio.h>
main()
{
	int i,j,k,a[2][2],b[2][2],c[2][2];
	clrscr();
	printf("Enter the Matrix A\n");
	i=0;
	while(i<2)
	{
		j=0;
		while(j<2)
		{
			scanf("%d",&a[i][j]);
			j++;
		}
		i++;
	}
	printf("Enter the Matrix B\n");
	i=0;
	while(i<2)
	{
		j=0;
		while(j<2)
		{
			scanf("%d",&b[i][j]);
			j++;
		}
		i++;
	}
	i=0;
	while(i<2)
	{
		j=0;
		while(j<2)
		{
		  k=0;
		  c[i][j]=0;
		  while(k<2)
		  {
			c[i][j]=c[i][j]+a[i][k]*b[k][j];
			k++;
		  }
		  j++;
		}
		i++;
	}
	printf("Result Matrix \n");
	i=0;
	while(i<2)
	{
		j=0;
		while(j<2)
		{
			printf("%d  ",c[i][j]);
			j++;
		}
		i++;
		printf("\n");
	}
	getch();
}

/* input: Enter Matrix A  2 3
			  4 6
	  Enter Matrix B  4 5
			  3 4

 How the loop will be executed
	a[0][0]=2  a[0][1]=3   a[1][0]=4    a[1][1]=6
	b[0][0]=4  b[0][1]=5   b[1][0]=3    b[1][1]=4
 Step 1: i=0,j=0,k=0
	 c[0][0]=0   initially
	 substitute i,j,k values in calculation part
	 c[0][0]=c[0][0]+a[0][0]*b[0][0]
	 c[0][0]=0+2*4=8 then the inner loop will be incremented
 Step 2: i=0,j=0,k=1
	 c[0][0]=c[0][0]+a[0][1]*b[1][0]
	 c[0][0]=8+3*3=17 then the inner loop will be executed
	 i=0,j=0,k=2 substitue these values the inner loop k will be false
		     so the loop will be transfered to j th loop and incremented the value
 Step 3: i=0,j=1,k=0
	 c[0][1]=0
	 c[0][1]=c[0][1]+a[0][0]*b[0][1]
	 c[0][1]=0+2*5 = 10
 Step 4: i=0,j=1,k=1
	 c[0][1]=c[0][1]+a[0][1]*b[1][1]
	 c[0][1]=10+3*4=10+12=22

	 i=0,j=1,k=2 substitue these values the inner loop k will be false
		     so the loop will be transfered to j th loop and incremented the value
	 i=0,j=2,k=2 substitue these values the inner loop j will be false
		     so the loop will be transfered to i th loop and incremented the value
 Step 5: i=1,j=0,k=0
	 c[1][0]=0
	 c[1][0]=c[1][0]+a[1][0]*b[0][0]
	 c[1][0]=0+4*4 = 16
 Step 6: i=1,j=0,k=1
	 c[1][0]=c[1][0]+a[1][1]*b[1][0]
	 c[1][0]=16+6*3=16+18=34
 Step 7: i=1,j=0,k=2 substitue these values the inner loop k will be false
		     so the loop will be transfered to j th loop and incremented the value
 Step 8: i=1,j=1,k=0
	 c[1][1]=0
	 c[1][1]=c[1][1]+a[1][0]*b[0][1]
	 c[1][1]=0+4*5=20      loop will be incremented
 Step 9: i=1,j=1,k=1
	 c[1][1]=20
	 c[1][1]=c[1][1]+a[1][1]*b[1][1]
	 c[1][1]=20+6*4=20+24=44 loop will be incremented
	 i=1,j=1,k=2 loop will be wrong
	 i=1,j=2,k=0 loop will be wrong
	 i=2,j=0,k=0 loop will be wrong

	 Note: The outer loop value i is 2 so the outer and inner loop cant be executed

	 The result of matrix C is : 17 22
				     34 44
	 hence the program */


/* Exercise: 1. Transpose of 2 * 2 Matrix
	     2. Order of m * n matrix to calculate addition, substraction, multiplication
		Hint: m is represented by number of rows and n is represented by number of columns
*/