C Program to find the product of any two matrices

C Program to find the product of any two matrices

This page has a C Program to find the product of any two matrices. We can write a C program to find the product of any two matrices. This program will multiply any sizes of two matrices. Here it is remember that, the number of columns of A matrix must be equal to the number of rows of B matrix. If not, the matrix multiplication is not possible. The below given C program is used to find the product of any two matrices. Kindly check out the program to find the product of matrices (matrix multiplication).

Program for Product of Two Matrices (Matrix multiplication) 


  #include<stdio.h>
  int main(){
          int matrixA[10][10], matrixB[10][10], matrixR[10][10];
          int r, s, t, m11, m12, m21, m22;
          clrscr();
          printf("\n Give size of A Matrix : \n");
          scanf("%d %d", &m11, &m12);
          printf("\n Give size of B Matrix : \n");
          scanf("%d %d", &m21, &m22);
          if(m12 == m21){
          printf("\n Enter Matrix A : \n"); // Read Matrix A
          for (r = 1; r <= m11; r++){
          for (s = 1; s <= m12; s++){
          scanf("%d", &matrixA[r][s]);
          }
          }
          printf("\n Enter Matrix B : \n"); // Read Matrix B
          for (r = 1; r <= m21; r++){
          for (s = 1; s <= m22; s++){
          scanf("%d", &matrixB[r][s]);
          }
          }
          printf("\n The Matrix A is : \n\n"); // Display A Matrix
          for (r = 1; r <= m11; r++){
          for (s = 1; s <= m12; s++){
          printf("\t %d ", matrixA[r][s]);
          }
          printf("\n");
          }
          printf("\n The Matrix B is : \n\n"); // Display B Matrix
          for (r = 1; r <= m21; r++){
          for (s = 1; s <= m22; s++){
          printf("\t %d ", matrixB[r][s]);
          }
          printf("\n");
          }

   // . . . The two matrices are multipled together . . .

          for (r = 1; r <= m11; r++){
          for (s = 1; s <= m22; s++){
          matrixR[r][s] = 0;
          for (t = 1; t <= m12; t++){
          matrixR[r][s] = matrixR[r][s]+ matrixA[r][t] * matrixB[t][s];
          }
          }
          }

   // . . . Product Matrix is printed in Matrix form . . .

          printf("\n\n The Product Matrix is \n\n");
          for (r = 1; r <= m11; r++){
          for (s = 1; s <= m22; s++){
          printf("\t%d", matrixR[r][s]);
          }
          printf("\n");
          }
          }
          else
          printf("\n\n The Matrix sizes are not possible to multiply");
          getch();
          return (0);
          }



Sample Output:


Give size of A Matrix :   4    3


Give size of B Matrix :   3    4


Enter Matrix A : 

2       2       2       2       2       2       2       2       2       2       2       2


Enter Matrix B :  

2       2       2       2       2       2       2       2       2       2       2       2


 The Matrix A is : 

2          2         2

2          2         2

2          2         2

2          2          2


 The Matrix B is : 

2          2         2         2

2          2         2          2

2          2         2         2

The Product Matrix is 

12          12           12          12

12          12          12          12

12          12           12          12

/12          12          12          12


Related Popular Posts:


*  Write a c program to check whether a given number is prime number or not?

 

*  Write a C program to find the prime numbers between 1 and 100

 

*  Write a C program to display the prime numbers between a range ?

 

*  Write a C program to find the prime numbers between a range using while loop?

 

*  Write a C program to find the sum of prime numbers between a range 

About Er. T.Tharesh Kumar

I am a Professor and Head of Department of Computer Science in an Arts and Science College. I have designed this website to provide solved example programs of different categories for all the school and college going students to learn C language deeply, and to practice Interview based Multiple Choice (Objective Type) questions and answers.

Other Related C Programs :


* C Program to find whether the given number is Odd or Even

* C Program to find the Sum of Odd Digits

* C Program to find the Sum of Even Digits

* C Program to find the Sum of Even and Odd Digits,

* C Program to Display Odd digits

* C Program to Display even digits

* C Program to Display Odd Numbers,

* C Program to Display Even Numbers,

* C Program to Check whether the given number is Armstrong number

* C Program to display the Armstrong numbers in Range

* C Program to display the Armstrong numbers between 1 and 1000

* C Program to check perfect number, perfect numbers in range

* C Program to Check Prime number, Prime numbers between 1 and 100

* C Program to display the Prime numbers in a Range

* C Program to display the Sum of Prime numbers

* C Program to Check Strong number

* C Program to display the Strong number in Range

* C Program to Check whether the given number is polindrome number or not

* C Program to Check polindrome number using for loop

* C Program to Check polindrome number using Recursion

* C Program to  check whether the given string is polindrome or not

* C Program to find the Roots of Quadratic equation

* C Program to display Fibonacci Series

* C Program to display the Fibonacci Series using an array

* C Program to display the Fibonacci Series using while loop

* C Program to find the Sum of Fibonacci Series, Factorial of Number

* C Program to find the Factorial without using Recursion

* C Program to find the Factorial using Pointers

* C Program to find the Factorial using Function

Bookmark and Share