Recursive Matrix Multiplication

Description:           This program performs the multiplication of two 4×4 matrices using recursion.
 
Primary Inputs:    Two 4×4 matrices
Primary Output:    Multiplication of the two matrices
Platform Used:      Turbo C++ version 3.0, Borland International Inc.
 

/*This program calculates the multiplication of two 4x4 matrices using recursion*/

#include
#include
int a[4][4],b[4][4],c[4][4];
int multi(int,int,int);
void main()
{
int i,x;
clrscr();
printf("\n enter the matrix A : \n");
for(i=0;i<4;i++) scanf("%d%d%d%d",&a[i][0],&a[i][1],&a[i][2],&a[i][3]); printf("\n Enter the matrix B :\n"); for(i=0;i<4;i++) { scanf("%d%d%d%d",&b[i][0],&b[i][1],&b[i][2],&b[i][3]); c[i][0]=0; c[i][1]=0; c[i][2]=0; c[i][3]=0; } x=multi(0,0,0); printf("\n The two matrices & there product is : "); for(i=0;i<4;i++) { printf("\n %d %d %d %d",a[i][0],a[i][1],a[i][2],a[i][3]); printf("\t %d %d %d %d",b[i][0],b[i][1],b[i][2],b[i][3]); printf("\t\t %d %d %d %d",c[i][0],c[i][1],c[i][2],c[i][3]); } getch(); } int multi(int i,int j,int k) { int x; if(k<4) if(i<4) if(j<4) { c[k][i]=c[k][i]+a[k][j]*b[j][i]; x=multi(i,j+1,k); if(j==3||j!=0) return 0; x=multi(i+1,j,k); if(i==3||i!=0) return 0; multi(i,j,k+1); } }

 

Rate this post

Leave a Reply