From 0f92f4c5e93664c801abf5f1ff3970874c9b8eaa Mon Sep 17 00:00:00 2001 From: raakesh1305 <84133959+raakesh1305@users.noreply.github.com> Date: Sun, 16 May 2021 12:41:40 +0530 Subject: [PATCH] Update calculator.c --- calculator.c | 116 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 16 deletions(-) diff --git a/calculator.c b/calculator.c index e27b986..216cfa1 100644 --- a/calculator.c +++ b/calculator.c @@ -1,5 +1,6 @@ #include #include +#include // 1. Addition void calcAddition() { @@ -10,32 +11,99 @@ void calcAddition() { printf("The sum is %d\n", result); } -// Fill the rest of the functionality here! -// 2. Subtraction -// 3. Multiplication +// 2. Subtraction +void calcSubtraction() { +printf("\nEnter two numbers: \n"); + int a,b; + scanf("%d%d",&a,&b); + int result = a-b; printf("The difference is %d\n",result); +} +// 3. Multiplication +void calcMultiplication() { + printf("\nEnter two numbers: \n"); + int a,b; + scanf("%d%d",&a,&b); + int result = a*b; + printf("Multiplication of the given two nummber is %d\n",result); + } // 4. Division -// 5. Exponentiation + void calcDivision() { + printf("\nEnter two numbers a and b like a greater than b: \n"); + int a,b; + scanf("%d%d",&a,&b); + int result = a/b; + printf("Division of the given two nummber is %d\n",result); + } +// 5. Exponentiation +void calcExponential() { + printf("\nEnter two numbers a and b like a greater than b: \n"); + int a,b; + scanf("%d%d",&a,&b); + int result = a^b; + printf("Division of the given two nummber is %d\n", result); +} // 6. Sine void calcSine() { printf("\nEnter the angle in degrees: "); int angle; scanf("%d", &angle); - - // Convert degrees to radians double radians = angle / 180.0 * 3.14; - double answer = sin(radians); - - printf("The sine value is %f", answer); + double result = sin(radians); + printf("\nThe sin of the given angle is %f\n",result); } - -// Fill the rest of the functionality here! // 7. Cosine +void calcCos() { + printf("\nEnter the angle in degrees: "); + int angle; + scanf("%d", &angle); + double radians = angle / 180.0 * 3.14; + double result = cos(radians); + printf("\nThe cos of the given angle is %f\n",result); +} // 8. Tangent +void calcTan() { + printf("\nEnter the angle in degrees: "); + int angle; + scanf("%d", &angle); + double radians = angle / 180.0 * 3.14; + double result = tan(radians); + printf("\nThe tan of the given angle is %f\n",result); +} + // 9. Floor +void calcFloor(){ + printf("\nEnter a numbers: \n"); + float a; + scanf("%f", &a); + int result = floor(a); + printf("\nThe floor of the number is %d\n",result); +} + // 10. Ceiling +void calcCeil(){ + printf("\nEnter a numbers: \n"); + float a; + scanf("%f", &a); + int result = ceil(a); + printf("\nThe ceil of the number is %d\n",result); +} // 11. Round +void calcRound(){ + printf("\nEnter a numbers: \n"); + float a; + scanf("%f", &a); + int result = round(a); + printf("\nThe rpund of the number is %d\n",result); +} // 12. Absolute value +void calcAbs(){ + printf("\nEnter a numbers: \n"); + int a; + scanf("%d", &a); + int result = abs(a); + printf("\nThe absolute value of the number is %d\n",result); +} int main() { int choice; @@ -62,25 +130,41 @@ int main() { case 1: calcAddition(); break; - case 2: + calcSubtraction(); + break; case 3: + calcMultiplication(); + break; case 4: + calcDivision(); + break; case 5: - - // 6. Sine + calcExponential(); + break; case 6: calcSine(); break; - case 7: + calcCos(); + break; case 8: + calcTan(); + break; case 9: + calcFloor(); + break; case 10: + calcCeil(); + break; case 11: + calcRound(); + break; case 12: + calcAbs(); + break; default: printf("Invalid choice!"); } return 0; -} \ No newline at end of file +}