You are on page 1of 2

#include<stdio.

h>
int result[10][10],;
void sum(int ar1[][10], int ar2[][10], int,int);
void difference(int ar1[][10], int ar2[][10], int, int);
void product(int ar1[][10], int ar2[][10], int, int);
void main()
{
int array1[10][10], array2[10][10], result[10][10];
int row1, col1, row2, col2, choice;
printf("Enter the number of rows in the 1st matrix\n");
scanf("%d", &row1);
printf("Enter the number of columns in the 1st matrix\n");
scanf("%d", &col1);
printf("Enter the number of rows in the 2nd matrix\n");
scanf("%d", &row2);
printf("Enter the number of columns in the 2nd matrix\n");
scanf("%d", &col2);
printf("Enter the elements of the 1st matrix\n");
for (int i = 0; i < row1; i++)
for (int j = 0; j < col1; j++)
scanf("%d", &array1[i][j]);
printf("Enter the elements of the 2nd matrix\n");
for (int i = 0; i < row2; i++)
for (int j = 0; j < col2; j++)
scanf("%d", &array2[i][j]);
if ((row1 == row2) && (col1 == col2))
sum(array1, array2, row1, col2);
else
printf("sum not allowed");
if ((row1 == row2) && (col1 == col2))
difference(array1, array2, row1, col2);
else
printf("difference not allowed");
if ((row1 == col2))
product(array1, array2, row1, col2);
else
printf("product not allowed");
}
void sum(int ar1[][10], int ar2[][10], int r, int c)
{
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
result[i][j] = ar1[i][j] + ar2[i][j];
printf("The sum of two matrices are\n");
for (int i = 0; i < r; i++)
{
printf("\n");
for (int j = 0; j < c; j++)
printf("%d\t", result[i][j]);
}
}
void difference(int ar1[][10], int ar2[][10], int r, int c)
{
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
result[i][j] = ar1[i][j] - ar2[i][j];
printf("\nThe difference of two matrices are\n");
for (int i = 0; i < r; i++)
{
printf("\n");
for (int j = 0; j < c; j++)
printf("%d\t", result[i][j]);
}
}
void product(int ar1[][10], int ar2[][10], int r, int c)
{
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
{
result[i][j] = 0;
for (int k = 0; k < c; k++)
result[i][j] = result[i][j] + ar1[i][k] * ar2[k][j];

}
printf("\nThe multiplication of two matrices are \n");
for (int i = 0; i < r; i++)
{
printf("\n");
for (int j = 0; j < c; j++)
printf("%d\t", result[i][j]);
}
printf("\n");
}