#include<stdio.h>
#include<conio.h>
int main()
{
int row, column,calc,i,j,k,first[10][10],second[10][10], result[10][10];
clrscr();
printf("Enter the number of rows and columns: \n");
scanf("%d%d", &row,&column);
printf("Enter the first element: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
scanf("%d",&first[i][j]);
}
}
printf("Enter the second element: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
scanf("%d",&second[i][j]);
}
}
printf("\n Matrix Addition : 1");
printf("\n Matrix Subtraction : 2");
printf("\n Matrix Multiplication : 3");
printf("\n Enter Your Choice : ");
scanf("%d",&calc);
switch(calc)
{
case 1:
printf("Result of Matrix Addition: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
result[i][j] = first[i][j]+second[i][j];
printf("%d\t",result[i][j]);
}
printf("\n");
}
break;
case 2:
printf("Result of Matrix Subtraction: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
result[i][j] = first[i][j]-second[i][j];
printf("%d\t",result[i][j]);
}
printf("\n");
}
break;
case 3:
printf("Result of Matrix Multiplication: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
result[i][j] = 0;
for(k=0;k<row;k++)
{
result[i][j] = result[i][j]+(first[i][k]*second[k][j]);
}
// result[i][j] = first[i][j]*second[i][j];
printf("%d\t",result[i][j]);
}
printf("\n");
}
break;
default:
printf("\nInvalid Choice");
}
getch();
return 0;
}
#include<conio.h>
int main()
{
int row, column,calc,i,j,k,first[10][10],second[10][10], result[10][10];
clrscr();
printf("Enter the number of rows and columns: \n");
scanf("%d%d", &row,&column);
printf("Enter the first element: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
scanf("%d",&first[i][j]);
}
}
printf("Enter the second element: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
scanf("%d",&second[i][j]);
}
}
printf("\n Matrix Addition : 1");
printf("\n Matrix Subtraction : 2");
printf("\n Matrix Multiplication : 3");
printf("\n Enter Your Choice : ");
scanf("%d",&calc);
switch(calc)
{
case 1:
printf("Result of Matrix Addition: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
result[i][j] = first[i][j]+second[i][j];
printf("%d\t",result[i][j]);
}
printf("\n");
}
break;
case 2:
printf("Result of Matrix Subtraction: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
result[i][j] = first[i][j]-second[i][j];
printf("%d\t",result[i][j]);
}
printf("\n");
}
break;
case 3:
printf("Result of Matrix Multiplication: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
result[i][j] = 0;
for(k=0;k<row;k++)
{
result[i][j] = result[i][j]+(first[i][k]*second[k][j]);
}
// result[i][j] = first[i][j]*second[i][j];
printf("%d\t",result[i][j]);
}
printf("\n");
}
break;
default:
printf("\nInvalid Choice");
}
getch();
return 0;
}