121 lines
2.4 KiB
C
121 lines
2.4 KiB
C
#include <math.h>
|
|
#include <stdio.h>
|
|
|
|
double exponent(double par)
|
|
{
|
|
double raisedNum;
|
|
raisedNum = par * par;
|
|
|
|
return raisedNum;
|
|
};
|
|
|
|
double hypotenuse(double par, double par2)
|
|
{
|
|
|
|
double sideC;
|
|
sideC = sqrt(exponent(par) + exponent(par2));
|
|
|
|
return sideC;
|
|
};
|
|
|
|
void quadratic(double numA, double numB, double numC, double *awn1ptr, double *awn2ptr)
|
|
{
|
|
|
|
double awn1 = (-numB) + sqrt(exponent(numB) - 4 * numA * numC);
|
|
double awn1F = awn1 / (2 * numA);
|
|
double awn2 = (-numB) - sqrt(exponent(numB) - 4 * numA * numC);
|
|
double awn2F = awn2 / (2 * numA);
|
|
|
|
*awn1ptr = awn1F;
|
|
*awn2ptr = awn2F;
|
|
};
|
|
|
|
double areaOfCircle(double radius)
|
|
{
|
|
|
|
double area;
|
|
area = acos(-1) * exponent(radius);
|
|
|
|
return area;
|
|
}
|
|
|
|
// int buildMatrix(int numRows, int numColumns)
|
|
// {
|
|
|
|
// int matrix[numRows][numColumns];
|
|
|
|
// printf("\nEnter elements in matrix of size %dx%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;
|
|
// }
|
|
//TODO: rewrite matrix builder
|
|
|
|
void printMatrix(int row, int col, int m[row][col])
|
|
{
|
|
for (int i = 0; i < row; i++)
|
|
{
|
|
for (int j = 0; j < col; j++)
|
|
{
|
|
printf("%d ", m[row][col]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
return;
|
|
}
|
|
|
|
void addMatrices(int r, int c, int m1[r][c], int m2[r][c], int mr[r][c])
|
|
{
|
|
for (int i = 0; i < r; i++)
|
|
{
|
|
for (int j = 0; j < c; j++)
|
|
{
|
|
mr[i][j] = m1[i][j] + m2[i][j];
|
|
}
|
|
}
|
|
}
|
|
|
|
int scalarMultiplication(int numRows, int numColumns, int scalar)
|
|
{
|
|
|
|
int matrix[numRows][numColumns];
|
|
|
|
printf("\nEnter elements in matrix of size %dx%d \n", numRows, numColumns);
|
|
|
|
for (int i = 0; i < numRows; i++)
|
|
{
|
|
for (int j = 0; j < numColumns; j++)
|
|
{
|
|
scanf("%d", &matrix[i][j]);
|
|
}
|
|
}
|
|
|
|
printf("\nScaled matrix is: \n");
|
|
for (int i = 0; i < numRows; i++)
|
|
{
|
|
for (int j = 0; j < numColumns; j++)
|
|
{
|
|
printf("%d ", matrix[i][j]*scalar);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
return 0;
|
|
} |