split functions into formulas and matrix functions
This commit is contained in:
parent
581ea39bbd
commit
3cb11a08b6
40
formulas.h
Normal file
40
formulas.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.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;
|
||||||
|
}
|
121
functions.h
121
functions.h
|
@ -1,121 +0,0 @@
|
||||||
#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;
|
|
||||||
}
|
|
114
matrices.h
Normal file
114
matrices.h
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
#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, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
// }
|
Loading…
Reference in a new issue