C Programming
Computer Programming

Program in C to Multiply to Matrix Using Multi-dimensional Arrays



Write a Program in c to Multiply to Matrix Using Multi-dimensional Arrays

\* C Program to to Multiply to Matrix Using Multi-dimensional Arrays *\

# include < stdio.h >
int   main( )
{

int   a[10][10], b[10][10], mul[10][10], i, j, k, r, c, sum  ;
printf(" Enter the Numbers of Row : ") ;
scanf("%d ", & r) ;
printf("\n Enter the Number of Coloumn : ") ;
scanf("%d ", & c) ;

printf("\n Enter the Element of First Matrix : \n") ;
for (  i = 0 ; i < r ; i++ )
{

for (  j = 0 ; j < c ; i++ )
{

printf("\n Enter the Element [%d] [%d] : " ,i, j) ;
scanf("%d ", & a[i][j]) ;

}

}

printf("\n Enter the Element of Second Matrix : \n") ;
for (  i = 0 ; i < r ; i++ )
{

for (  j = 0 ; j < c ; i++ )
{

printf("\n Enter the Element [%d] [%d] : " ,i, j) ;
scanf("%d ", & b[i][j]) ;

}

}

printf("\n\n Element in the first Matrix are : \n") ;
for (  i = 0 ; i < r ; i++ )
{

for (  j = 0 ; j < c ; i++ )
{

printf("\t %d ",  a[i][j]) ;

}
printf(" \n ") ;

}

printf("\n\n Element in Second Matrix are: \n") ;
for (  i = 0 ; i < r ; i++ )
{

for (  j = 0 ; j < c ; i++ )
{

printf("\t %d ",  b[i][j]) ;

}
printf(" \n ") ;

}

for (  i = 0 ; i < r ; i++ )
{

for (  j = 0 ; j < c ; i++ )
{

sum = 0 ;
for (  k = 0 ; k < r ; k++ )
{

sum = sum + ( a[i][k] * b[k][j] )  ;

}
mul[i][j] = sum ;

}

}

printf("\n\n Multiplicaiton of Two Matrix are : \n") ;
for (  i = 0 ; i < r ; i++ )
{

for (  j = 0 ; j < c ; i++ )
{

printf("\t %d ",  mul[i][j]) ;

}
printf(" \n ") ;

}
return ( 0 ) ;

}

Output of Program :

Output of Program in C to Multiply to Matrix Using Multi-dimensional Arrays