/* Example: matrices represented by 2-dimensional arrays */

#include <stdio.h>

main()
{



  int i, j, k;
  int A[3][3];
  int B[3][3];


//Scan in A
  for(i=0; i<3; i++){
    for(j=0;j<3; j++){
      scanf("%d",&A[i][j]);//note that we use & here because we need to refer to A as a pointer
    }
  }

//Scan in B
  for(i=0; i<3; i++){
    for(j=0;j<3; j++){
      scanf("%d",&B[i][j]);//note that we use & here because we need to refer to B as a pointer
    }
  }

  //Print A
  printf("A   = ");
  for(i=0; i<3; i++){
    if(i==0){
     printf("[");
   }else{
    printf("      [");
  }
  for(j=0;j<3; j++){
      printf("%3i",A[i][j]);//note that we use & here because we need to refer to B as a pointer
      if(j==2){printf(" ");}else{printf("  ");}
    }
    printf("]\n");
  }
  printf("\n");


  int C[3][3];



   //Print B
  printf("B   = ");
  for(i=0; i<3; i++){
    if(i==0){
     printf("[");
   }else{
    printf("      [");
  }
  for(j=0;j<3; j++){
      printf("%3i",B[i][j]);//note that we use & here because we need to refer to B as a pointer
      if(j==2){printf(" ");}else{printf("  ");}
    }
    printf("]\n");
  }
  printf("\n");



  /* multiply C = A.B: */

  for (i = 0; i < 3; i++)
    for (j = 0; j < 3; j++)
    {
      C[i][j] = 0;
      for (k =0; k < 3; k++)
        C[i][j] += A[i][k] * B[k][j];
    }

    printf("A.B = ");
    for(i=0; i<3; i++){
      if(i==0){
       printf("[");
     }else{
      printf("      [");
    }
    for(j=0;j<3; j++){
      printf("%3i",C[i][j]);//note that we use & here because we need to refer to B as a pointer
      if(j==2){printf(" ");}else{printf("  ");}
    }
    printf("]\n");
  }
  printf("\n");

  /* multiply C = B.A: */

  for (i = 0; i < 3; i++)
    for (j = 0; j < 3; j++)
    {
      C[i][j] = 0;
      for (k =0; k < 3; k++)
        C[i][j] += B[i][k] * A[k][j];
    }

     printf("B.A = ");
    for(i=0; i<3; i++){
      if(i==0){
       printf("[");
     }else{
      printf("      [");
    }
    for(j=0;j<3; j++){
      printf("%3i",C[i][j]);//note that we use & here because we need to refer to B as a pointer
      if(j==2){printf(" ");}else{printf("  ");}
    }
    printf("]\n");
  }
  printf("\n");


  }