Code Scrappers


Multiplication Of Two Matrices C program


              #include<stdio.h>
              #include<stdlib.h>

              int main()
              {
                  int a[10][10], b[10][10], c[10][10], i, j, k;

                  int sum = 0;

                  printf("\nEnter elements of First Matrix : n");

                  for (i = 0; i < 3; i++)
                  {
                        for (j = 0; j < 3; j++)
                        {
                            scanf("%d", &a[i][j]);
                        }
                  }

                  printf("\nEnter elements of Second Matrix:n");

                  for (i = 0; i < 3; i++)
                  {
                      for (j = 0; j < 3; j++)
                      {
                          scanf("%d", &b[i][j]);
                      }
                  }

                  printf("The First Matrix is: \n");

                  for (i = 0; i < 3; i++)
                  {
                      for (j = 0; j < 3; j++)
                      {
                          printf(" %d ", a[i][j]);
                      }
                      printf("\n");
                 }

                 printf("The Second Matrix is : \n");

                 for (i = 0; i < 3; i++)
                 {
                      for (j = 0; j < 3; j++)
                      {
                          printf(" %d ", b[i][j]);
                      }
                    printf("\n");
                 }

                 for (i = 0; i <= 2; i++)
                 {
                      for (j = 0; j <= 2; j++)
                      {
                          sum = 0;

                          for (k = 0; k <= 2; k++)
                          {
                              sum = sum + a[i][k] * b[k][j];
                          }

                          c[i][j] = sum;
                      }
                 }

                 printf("\nMultiplication Of Two Matrices is : \n");

                 for (i = 0; i < 3; i++)
                 {
                      for (j = 0; j < 3; j++)
                      {
                          printf(" %d ", c[i][j]);
                      }

                      printf("\n");
                 }

                 return (0);
              }


          



Output

            Enter Second Matrix:n9
        8
        7
        6
        5
        4
        3
        2
        1
        The First Matrix is:
         1  2  3
         4  5  6
         7  8  9
        The Second Matrix is :
         9  8  7
         6  5  4
         3  2  1

        Multiplication Of Two Matrices :
         30   24   18
         84   69   54
         138  114  90