diff --git a/README.md b/README.md index 7ddb52d..5569304 100644 --- a/README.md +++ b/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 @@ -28,11 +31,4 @@ My goal for this project is to write an open sourced mathmatical library for C a - 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 \ No newline at end of file +- Integral \ No newline at end of file diff --git a/formulas.h b/formulas.h index bdc9ec7..0c6f9df 100644 --- a/formulas.h +++ b/formulas.h @@ -29,4 +29,19 @@ double areaOfCircle(double radius) area = acos(-1) * pow(radius, 2); return area; -} \ No newline at end of file +}; + +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); +}; \ No newline at end of file diff --git a/main.c b/main.c index 9d9c5fd..7f8bf4f 100644 --- a/main.c +++ b/main.c @@ -18,6 +18,8 @@ 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\n * Stared entries are not fully programmed."); printf("\n Enter your choice here:_____"); @@ -133,8 +135,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 +144,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");