Commit bc9e045d by emonyi

Upload New File

parent 7b4ae79f
Showing with 94 additions and 0 deletions
#include <stdio.h>
int main()
{
int dimension, x, y;
printf("please enter the rows and columns of the two square matrices: ");
scanf("%d", &dimension);
int marray1[dimension][dimension];
int marray2[dimension][dimension];
printf("enter the values of the first matrix:\n");
for(x = 0; x < dimension; x++)
{
for(y = 0; y < dimension; y++)
{
scanf("%d", &marray1[x][y]);
}
}
printf("The first matrix is:\n");
for(x = 0; x < dimension; x++)
{
for(y = 0; y < dimension; y++)
{
printf("%d, ", marray1[x][y]);
}
printf("\n");
}
printf("enter the values of the second matrix:\n");
for(x = 0; x < dimension; x++)
{
for(y = 0; y < dimension; y++)
{
scanf("%d", &marray2[x][y]);
}
}
printf("The second matrix is:\n");
for(x = 0; x < dimension; x++)
{
for(y = 0; y < dimension; y++)
{
printf("%d, ", marray2[x][y]);
}
printf("\n");
}
printf("\nThe sum of entered matrices are:\n");
int sum[dimension][dimension];
for(x = 0; x < dimension; x++)
{
for(y = 0; y < dimension; y++)
{
sum[x][y] = marray1[x][y] + marray2[x][y];
printf("%d, ", sum[x][y]);
}
printf("\n");
}
printf("\nThe difference of entered matrices are:\n");
int diff[dimension][dimension];
for(x = 0; x < dimension; x++)
{
for(y = 0; y < dimension; y++)
{
diff[x][y] = marray1[x][y] - marray2[x][y];
printf("%d, ", diff[x][y]);
}
printf("\n");
}
printf("\nThe sum of products of diagonals of the first matrices are:\n");
int product1 = 1;
for(x = 0; x < dimension; x++)
{
product1 = product1 * marray1[x][x];
}
int product2 = 1;
for(x = 0; x < dimension; x++)
{
product2 = product2 * marray1[x][dimension-1-x];
}
printf("%d", product1 + product2);
printf("\nThe sum of products of diagonal of the second matrices are:\n");
int product3 = 1;
for(x = 0; x < dimension; x++)
{
product3 = product3 * marray2[x][x];
}
int product4 = 1;
for(x = 0; x < dimension; x++)
{
product4 = product4 * marray2[x][dimension-x-1];
}
printf("%d", product3 + product4);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment