# C Program to multiply two matrices using Recursion

## C Program to multiply two matrices using Recursion

This page has a C Program to multiply two matrices using Recursion. It is clear that, this C program will display the product of any Two Matrices using Recursion. To multiply (find product) any two matrices using Recursion, the number of columns of the first matrix must be equal to the number of rows  of the the second matrix. If the size of A matrix is (5 x 3), and the size of B matrix is (3 x 4), then the two matrices can be multiplied using RecursionIf the size of A matrix is (4 x 3), and the size of B matrix is (4 x 2), then the two matrices can not be multiplied using RecursionFor multiplying any two matrices using Recursion, the two matrices must be compatible. The below given C program will find the product (Multiply) of any Two Matrices using Recursion. Kindly check out the program to Multiply any Two Matrices using Recursion. The Questions for the matrix multiplication program can be asked as . . .

1). C program to Multiply any Two n X n Matrices using Recursion.

2). C program to find the product of any Two m X m Matrices.

3). C program to Multiply one matrix with other using Recursion.

4). C program to find the product of any Two Matrices using Recursion.

5). C program to Multiply any Two Matrices using Recursion

6). C program to find the product of any Two Matrices using Recursion

7). C program to Multiply one matrix with other on same size

8). C program to find the product of any Two square Matrices

9). C program to find the product of Two 3 X 3 Matrices using Recursion

10). C program to find product of Two Matrices using Recursion

11). C program to multiply Two 3 X 3 Matrices using Recursion

12). C program to multiply Two Matrices using Recursion

13). C program to print the product of Two Matrices using Recursion

14). C program to display the product of Two Matrices using Recursion

### Program for Product of Two Matrices

#include<stdio.h>
void product(int matrix1[20][20], int a, int b, int matrix2[20][20], int c, int d, int products[20][20]){
static int x=1,y=1,z=1;
if(x<=a){
if(y<=d){
if(z<=b){
products[x][y] += matrix1[x][z]*matrix2[z][y];
z++;
product(matrix1, a, b, matrix2, c, d, products);
}
z=1;
y++;
product(matrix1, a, b, matrix2, c, d, products);
}
y=1;
x++;
product(matrix1, a, b, matrix2, c, d, products);
}
}

int main(){
int m1[20][20], m2[20][20], products[20][20];
int x, y, z, m, n, p, q;
clrscr();
printf(" Enter your First Matrix size : \n");
scanf("%d %d", &m, &n);
printf("\n Enter your Second Matrix size :\n");
scanf("%d %d", &p, &q);
if(n==p){
printf("\nEnter the elements of  1st Matrix : \n");
for (x = 1; x <= m; ++x) {
for (y = 1; y <= n; ++y) {
scanf("%d", &m1[x][y]);
}
}
printf("\nEnter the elements of 2nd Matrix: \n");
for (x = 1; x <= p; ++x) {
for (y = 1; y <= q; ++y) {
scanf("%d", &m2[x][y]);
}
}
printf("\n The First Matrix is  . . . \n\n");
for (x = 1; x <= m; ++x) {
for (y = 1; y <= n; ++y) {
printf("\t %d ", m1[x][y]);
}
printf("\n");
}
printf("\n The Second Matrix is  . . . \n\n");
for (x = 1; x <= p; ++x){
for (y = 1; y <= q; ++y){
printf("\t %d ", m2[x][y]);
}
printf("\n");
}
for (x = 1; x <= m; ++x)
for (y = 1; y <= q; ++y)
products[x][y] = 0;
product(m1, m, n, m2, p, q, products);
printf("\n\n The Product of two matrices using Recursion is . . .\n\n");
for (x = 1; x <= m; ++x){
for (y = 1; y <= q; ++y){
printf("\t%d", products[x][y]);
}
printf("\n\n");
}
}
else
printf("\n\n The two Matrices are not compatible to Multiply !! \n\n");
getch();
return(0);
}

Sample Output:

Enter your First Matrix size :
4       3

Enter your Second Matrix size :
3       4

Enter the elements of  1st Matrix :

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

Enter the elements of 2nd Matrix:

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

The First Matrix is  . . .

2          2         2

2          2         2

2          2         2

2          2          2

The Second Matrix is  . . .

2          2         2         2

2          2         2          2

2          2         2         2

The Product of two matrices using Recursion 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