Multiplication of matrix

To find the product of two we use arrays to define a matrix size and then using loops the multiplication prosedure is done for the matrices.

Inputs to the script

User has to enter matrix size and elements


By looping through elements the multiplication is done.

Output of the script

We will get product of the matrix in matrix form
#include <stdio.h>
int main()
  int i, j, k, q, c, d, a, sum = 0;
  /// i is number of rows in 1st matrix and j is nmber of coloumns in 1st matrix
  ////k is no of rows in second matrix,q is no of coloumns in second matrix
  int first[10][10], second[10][10], multiply[10][10];
  printf("Enter number of rows and columns of first matrix\n");
  scanf("%d%d", &i, &j);
  printf("Enter elements of first matrix\n");
  for (c = 0; c < i; c++)
    for (d = 0; d < j; d++)
      scanf("%d", &first[c][d]);
  printf("Enter number of rows and columns of second matrix\n");
  scanf("%d%d", &k, &q);
  if (j!= k)
    printf("The matrices can't be multiplied with each other.\n");
    printf("Enter elements of second matrix\n");
    for (c = 0; c < k; c++)
      for (d = 0; d < q; d++)
        scanf("%d", &second[c][d]);
    for (c = 0; c < i; c++) {
      for (d = 0; d < q; d++) {
        for (a = 0; a < k; a++) {
          sum = sum + first[c][a]*second[a][d];
        multiply[c][d] = sum;
        sum = 0;
    printf("Product of the matrices:\n");
     for (c = 0; c < i; c++) {
      for (d = 0; d < q; d++)
        printf("%d", multiply[c][d]);
  return 0;
Addition & Subtraction of Matrix
Visitors Rating
Your Rating

Post your comments , suggestion , error , requirements etc here

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 All rights reserved worldwide Privacy Policy Disclaimer