Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
|
83505d30ae | ||
|
5429d6c121 | ||
|
7901a3a579 | ||
|
23ece9e47b | ||
|
761c706a29 | ||
|
e4b2b15243 | ||
|
ff218e15c8 | ||
|
8db7e59bb9 |
6 changed files with 69 additions and 19 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -51,5 +51,5 @@ Module.symvers
|
|||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# random shit I test
|
||||
# random shit
|
||||
test.c
|
12
README.md
12
README.md
|
@ -13,7 +13,10 @@ My goal for this project is to write an open sourced mathmatical library for C a
|
|||
## List of calculators
|
||||
|
||||
- Hypotenuse calculator (a²+b²=c²)
|
||||
- Circumference of a Circle
|
||||
- Area of a circle (πr²)
|
||||
- Area of a Triangle
|
||||
- Area of a Rectangle
|
||||
- Matrix arithmetics (2-D arrays)
|
||||
- Determinant of 2*2 matrix
|
||||
- Scalar multiplication
|
||||
|
@ -27,12 +30,3 @@ My goal for this project is to write an open sourced mathmatical library for C a
|
|||
- Matrix multiplication
|
||||
- Determinant of n*n matrix
|
||||
- Matrix support for none integer numbers
|
||||
- Derivative
|
||||
- Integral
|
||||
- Area
|
||||
- Area of a triangle
|
||||
- Area of a quadralateral
|
||||
- Peremeter
|
||||
- Peremeter of a triangle
|
||||
- Peremeter of a quadralateral
|
||||
- Circumference of a circle
|
17
formulas.h
17
formulas.h
|
@ -29,4 +29,19 @@ double areaOfCircle(double radius)
|
|||
area = acos(-1) * pow(radius, 2);
|
||||
|
||||
return area;
|
||||
}
|
||||
};
|
||||
|
||||
double areaOfTriangle(double height, double base)
|
||||
{
|
||||
return (height * base)*(1.0/2.0);
|
||||
};
|
||||
|
||||
double areaOfRectangle(double height, double base)
|
||||
{
|
||||
return (height * base);
|
||||
};
|
||||
|
||||
double circumferenceOfCircle(double radius)
|
||||
{
|
||||
return (2 * acos(-1) * radius);
|
||||
};
|
47
main.c
47
main.c
|
@ -18,6 +18,9 @@ int main()
|
|||
printf("\n 6. * Matrix multiplication *");
|
||||
printf("\n 7. Scalar matrix multiplication");
|
||||
printf("\n 8. Exponent");
|
||||
printf("\n 9. Area of Triangle");
|
||||
printf("\n 10. Area of Rectangle");
|
||||
printf("\n 11. Circumference of Circle");
|
||||
|
||||
printf("\n\n * Stared entries are not fully programmed.");
|
||||
printf("\n Enter your choice here:_____");
|
||||
|
@ -118,13 +121,13 @@ int main()
|
|||
|
||||
int numRows;
|
||||
int numColumns;
|
||||
int scalar;
|
||||
double scalar;
|
||||
printf("\nPlease enter the number of rows: ");
|
||||
scanf("%d", &numRows);
|
||||
printf("\nPlease enter the number of columns: ");
|
||||
scanf("%d", &numColumns);
|
||||
printf("\nPlease enter the scalar multiplier: ");
|
||||
scanf("%d", &scalar);
|
||||
scanf("%lf", &scalar);
|
||||
|
||||
scalarMultiplication(numRows, numColumns, scalar);
|
||||
|
||||
|
@ -133,8 +136,7 @@ int main()
|
|||
|
||||
system("clear");
|
||||
printf("\n ~~ Exponenet ~~\n\n");
|
||||
double base;
|
||||
double exp;
|
||||
double base, exp;
|
||||
printf("\nPlease enter the base: ");
|
||||
scanf("%lf", &base);
|
||||
printf("\nPlease enter the exponent: ");
|
||||
|
@ -143,6 +145,43 @@ int main()
|
|||
printf("%lf to the power of %lf is equal to %lf.\n", base, exp, num);
|
||||
|
||||
break;
|
||||
|
||||
case 9:
|
||||
system("clear");
|
||||
printf("\n ~~ Area of Triangle ~~\n\n");
|
||||
double triBase, triHeight;
|
||||
printf("\nPlease enter the base: ");
|
||||
scanf("%lf", &triBase);
|
||||
printf("\nPlease enter the height: ");
|
||||
scanf("%lf", &triHeight);
|
||||
double triArea = areaOfTriangle(triHeight, triBase);
|
||||
printf("The area of triangle is %lf.\n", triArea);
|
||||
|
||||
break;
|
||||
|
||||
case 10:
|
||||
system("clear");
|
||||
printf("\n ~~ Area of Rectangle ~~\n\n");
|
||||
double recBase, recHeight;
|
||||
printf("\nPlease enter the base: ");
|
||||
scanf("%lf", &recBase);
|
||||
printf("\nPlease enter the height: ");
|
||||
scanf("%lf", &recHeight);
|
||||
double recArea = areaOfRectangle(recHeight, recBase);
|
||||
printf("The area of rectangle is %lf.\n", recArea);
|
||||
|
||||
break;
|
||||
|
||||
case 11:
|
||||
system("clear");
|
||||
printf("\n ~~ Circumference of a Circle ~~\n\n");
|
||||
double cirRadius;
|
||||
printf("\nPlease enter the radius: ");
|
||||
scanf("%lf", &cirRadius);
|
||||
double circumference = circumferenceOfCircle(cirRadius);
|
||||
printf("The circumference is %lf.\n", circumference);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("\n Incorrect input, try again.\n");
|
||||
|
|
2
makefile
Normal file
2
makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
all:
|
||||
gcc main.c -lm -o "cli-calc.o"
|
|
@ -57,9 +57,9 @@ int matrixAddition(int numRows, int numColumns)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int scalarMultiplication(int numRows, int numColumns, int scalar)
|
||||
int scalarMultiplication(int numRows, int numColumns, double scalar)
|
||||
{
|
||||
int matrix[numRows][numColumns];
|
||||
double matrix[numRows][numColumns];
|
||||
|
||||
printf("\nEnter elements in matrix of size %d*%d! \n", numRows, numColumns);
|
||||
|
||||
|
@ -67,7 +67,7 @@ int scalarMultiplication(int numRows, int numColumns, int scalar)
|
|||
{
|
||||
for (int j = 0; j < numColumns; j++)
|
||||
{
|
||||
scanf("%d", &matrix[i][j]);
|
||||
scanf("%lf", &matrix[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ int scalarMultiplication(int numRows, int numColumns, int scalar)
|
|||
{
|
||||
for (int j = 0; j < numColumns; j++)
|
||||
{
|
||||
printf(" %d ", matrix[i][j] * scalar);
|
||||
printf(" %lf ", matrix[i][j] * scalar);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue