140 lines
No EOL
3 KiB
C
140 lines
No EOL
3 KiB
C
#include <stdio.h>
|
|
|
|
int matrixAddition(int numRows, int numColumns)
|
|
{
|
|
|
|
int matrix1[numRows][numColumns];
|
|
int matrix2[numRows][numColumns];
|
|
|
|
printf("\nEnter elements in the first matrix:\n");
|
|
|
|
for (int i = 0; i < numRows; i++)
|
|
{
|
|
for (int j = 0; j < numColumns; j++)
|
|
{
|
|
scanf("%d", &matrix1[i][j]);
|
|
}
|
|
}
|
|
printf("\nEnter elements in the second matrix:\n");
|
|
|
|
for (int i = 0; i < numRows; i++)
|
|
{
|
|
for (int j = 0; j < numColumns; j++)
|
|
{
|
|
scanf("%d", &matrix2[i][j]);
|
|
}
|
|
}
|
|
|
|
printf("\nFirst matrix is: \n");
|
|
for (int i = 0; i < numRows; i++)
|
|
{
|
|
for (int j = 0; j < numColumns; j++)
|
|
{
|
|
printf(" %d ", matrix1[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
printf("\nSecond matrix is: \n");
|
|
for (int i = 0; i < numRows; i++)
|
|
{
|
|
for (int j = 0; j < numColumns; j++)
|
|
{
|
|
printf(" %d ", matrix2[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
printf("\nSummed matrix is: \n");
|
|
for (int i = 0; i < numRows; i++)
|
|
{
|
|
for (int j = 0; j < numColumns; j++)
|
|
{
|
|
printf(" %d ", matrix1[i][j] + matrix2[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int scalarMultiplication(int numRows, int numColumns, double scalar)
|
|
{
|
|
double matrix[numRows][numColumns];
|
|
|
|
printf("\nEnter elements in matrix of size %d*%d! \n", numRows, numColumns);
|
|
|
|
for (int i = 0; i < numRows; i++)
|
|
{
|
|
for (int j = 0; j < numColumns; j++)
|
|
{
|
|
scanf("%lf", &matrix[i][j]);
|
|
}
|
|
}
|
|
|
|
printf("\nScaled matrix is: \n");
|
|
for (int i = 0; i < numRows; i++)
|
|
{
|
|
for (int j = 0; j < numColumns; j++)
|
|
{
|
|
printf(" %lf ", matrix[i][j] * scalar);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int determinant()
|
|
{
|
|
int det;
|
|
int matrix[2][2];
|
|
printf("\nEnter elements in matrix: \n");
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
for (int j = 0; j < 2; j++)
|
|
{
|
|
scanf("%d", &matrix[i][j]);
|
|
}
|
|
};
|
|
|
|
printf("\nElements in matrix are: \n");
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
for (int j = 0; j < 2; j++)
|
|
{
|
|
printf(" %d ", matrix[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
det = (matrix[0][0] * matrix[1][1]) - (matrix[0][1] * matrix[1][0]);
|
|
return det;
|
|
}
|
|
|
|
// int buildMatrix(int numRows, int numColumns)
|
|
// {
|
|
|
|
// int matrix[numRows][numColumns];
|
|
|
|
// printf("\nEnter elements in matrix of size %d*%d \n", numRows, numColumns);
|
|
|
|
// for (int i = 0; i < numRows; i++)
|
|
// {
|
|
// for (int j = 0; j < numColumns; j++)
|
|
// {
|
|
// scanf("%d", &matrix[i][j]);
|
|
// }
|
|
// }
|
|
|
|
// printf("\nElements in matrix are: \n");
|
|
// for (int i = 0; i < numRows; i++)
|
|
// {
|
|
// for (int j = 0; j < numColumns; j++)
|
|
// {
|
|
// printf(" %d ", matrix[i][j]);
|
|
// }
|
|
// printf("\n");
|
|
// }
|
|
|
|
// return 0;
|
|
// }
|