Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 100 additions & 16 deletions calculator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

// 1. Addition
void calcAddition() {
Expand All @@ -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;
Expand All @@ -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;
}
}