#include<stdio.h>
int main ()
{
int A[3][3],B[3][3],sum[3][3],sub[3][3],multi[3][3],div[3][3];
int i,j,rows,cols,add=0;
printf("Enter the value of rows & columns=\n");
scanf("%d%d", &rows,&cols);
printf("Enter Matrix A=\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
scanf("%d",&A[i][j]);
}
}
printf("Enter Matrix B=\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
scanf("%d",&B[i][j]);
}
}
printf("Addition of two matrix=\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
sum[i][j]=A[i][j]+B[i][j];
printf("%d\t",sum[i][j]);
}
printf("\n");
}
printf("Subtraction of two matrix=\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
sub[i][j]=A[i][j]-B[i][j];
printf("%d\t",sub[i][j]);
}
printf("\n");
}
printf("Multiplication of two matrix=\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
multi[i][j]=A[i][j]*B[i][j];
printf("%d\t",multi[i][j]);
}
printf("\n");
}
printf("Diagonal Matrix=\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if(i==j)
{
add=add+A[i][j];
}
printf("%d\n",add);
}
return 0;
}
}
