C Programming
Computer Programming

Program in C to Add Two Matrix Using Multi-dimensional Arrays



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

\* C Program to to Add Two Matrix Using Multi-dimensional Arrays *\

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

int   a[10][10], b[10][10], sum[10][10], i, j, r, c  ;
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[i][j] = a[i][j] + b[i][j] ;

}

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

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

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

}
printf(" \n ") ;

}
return ( 0 ) ;

}

Output of Program :

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