Browse Source

refactoring: case(geting user input for both int and double)

remotes/origin/Ulrich
Ulriche Nguefack 11 months ago
parent
commit
2957ef2229
  1. 40
      src/main/c/Calculator/calculator.c

40
src/main/c/Calculator/calculator.c

@ -115,32 +115,16 @@ double combination(int n, int r);
return 0.0; return 0.0;
} }
} }
double getDoubleInput(const char *message) {
double input;
printf("%s", message);
scanf("%lf", &input);
return input;
}
double power(double base, double exponent) {
return pow(base, exponent);
}
double sine(double angle) {
return sin(angle * M_PI / 180.0);
}
double cosine(double angle) {
return cos(angle * M_PI / 180.0);
}
double tangent(double angle) {
return tan(angle * M_PI / 180.0);
}
double permutation(int n, int r) {
int result = 1;
for (int i = 0; i < r; i++) {
result *= (n - i);
}
return result;
}
double combination(int n, int r) {
return permutation(n, r) / factorial(r);
}
int getIntInput(const char *message) {
int input;
printf("%s", message);
scanf("%d", &input);
return input;
}
Loading…
Cancel
Save