#include<stdio.h>
#define row 2
#define col 3
void mat_arith(int [][col], int [][col]); /* function prototype */
int main()
{
int a[row][col], b[row][col],i,j;
printf("\n Enter the elements of the first matrix.\n");
for(i=0; i<row; i++) /** Read first matrix elements **/
for(j=0; j<col; j++)
scanf("%d",&a[i][j]);
printf("\n Enter the elements of the second matrix.\n");
for(i=0; i<row; i++) /** Read second matrix elements **/
for(j=0; j<col; j++)
scanf("%d",&b[i][j]);
mat_arith(a,b); /** function call **/
}
void mat_arith(int a[][col], int b[][col])
{
int c[row][col],i,j,choice;
printf("\n For addition enter: 1 \n For subtraction enter: 2\n");
printf("\nEnter your choice: ");
scanf("%d",&choice);
for(i=0; i<row; i++)
for(j=0; j<col; j++)
{
if(choice==1)
c[i][j]= a[i][j] + b[i][j];
else if(choice==2)
c[i][j]= a[i][j] - b[i][j];
else
{
printf("\n Invalid choice. Task not done.");
return;
}
}
printf("\n The resulting matrix is:\n ");
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
printf("%d ", c[i][j]);
printf("\n\n ");
}
return;
}