You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
3.6 KiB
156 lines
3.6 KiB
// scientificMode
|
|
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
|
|
// get the number which has to be calculated
|
|
double getNumberFromUser() {
|
|
double num;
|
|
printf("Enter a number: ");
|
|
scanf("%lf", &num);
|
|
return num;
|
|
}
|
|
|
|
// Choice for ScientificMode
|
|
int getScientificModeChoice() {
|
|
int choice;
|
|
printf("Scientific mode Options:\n");
|
|
printf("1: Square root\n");
|
|
printf("2: Exponential\n");
|
|
printf("3: Logarithm\n");
|
|
printf("4: Trigonometric\n");
|
|
printf("0: Exit\n");
|
|
scanf("%d", &choice);
|
|
return choice;
|
|
}
|
|
|
|
// Choice for Logarithm
|
|
int getLogarithmChoice() {
|
|
int logChoice;
|
|
printf("Logarithm Options:\n");
|
|
printf("1: Logarithm (base 10)\n");
|
|
printf("2: Natural Logarithm (ln)\n");
|
|
printf("3: Logarithm (base 2)\n");
|
|
printf("0: Exit Logarithm Menu\n");
|
|
scanf("%d", &logChoice);
|
|
return logChoice;
|
|
}
|
|
|
|
// Choice for Trigonomtri
|
|
int getTrigonometricChoice() {
|
|
int trigChoice;
|
|
printf("Trigonometric functions:\n");
|
|
printf("1: Sine\n");
|
|
printf("2: Cosine\n");
|
|
printf("3: Tangent\n");
|
|
printf("0: Exit Trigonometric Menu\n");
|
|
scanf("%d", &trigChoice);
|
|
return trigChoice;
|
|
}
|
|
|
|
|
|
// Logarithm
|
|
void executeLogarithmFunction(double num) {
|
|
int logChoice;
|
|
|
|
do {
|
|
|
|
logChoice = getLogarithmChoice();
|
|
|
|
switch (logChoice) {
|
|
case 1: // Logarithm (base 10)
|
|
printf("Result: %lf\n", logarithmFunction(num));
|
|
break;
|
|
|
|
case 2: // Natural Logarithm (ln)
|
|
printf("Result: %lf\n", naturalLogarithmFunction(num));
|
|
break;
|
|
|
|
case 3: // Logarithm (base 2)
|
|
printf("Result: %lf\n", logarithmBase2Function(num));
|
|
break;
|
|
|
|
case 0: // Exit the logarithm menu
|
|
break;
|
|
|
|
default:
|
|
printf("Invalid logarithm function choice. Please try again.\n");
|
|
}
|
|
} while (logChoice != 0);
|
|
}
|
|
|
|
// Trigonometric
|
|
void executeTrigonometricFunction(double num) {
|
|
int trigChoice;
|
|
|
|
do {
|
|
|
|
trigChoice = getTrigonometricChoice();
|
|
|
|
switch (trigChoice) {
|
|
case 1: // Sine
|
|
printf("Result: %lf\n", sineFunction(num));
|
|
break;
|
|
|
|
case 2: // Cosine
|
|
printf("Result: %lf\n", cosineFunction(num));
|
|
break;
|
|
|
|
case 3: // Tangent
|
|
printf("Result: %lf\n", tangentFunction(num));
|
|
break;
|
|
|
|
case 0: // Exit the trigonometric menu
|
|
break;
|
|
|
|
default:
|
|
printf("Invalid trigonometric function choice. Please try again.\n");
|
|
}
|
|
} while (trigChoice != 0);
|
|
}
|
|
|
|
|
|
void executeScientificFunction(double num, int choice) {
|
|
double result;
|
|
|
|
switch (choice) {
|
|
case 1: // Square root
|
|
result = squareRootFunction(num);
|
|
printf("Result: %lf\n", result);
|
|
break;
|
|
|
|
case 2: // Exponential
|
|
result = exponentialFunction(num);
|
|
printf("Result: %lf\n", result);
|
|
break;
|
|
|
|
case 3: // Logarithm
|
|
executeLogarithmFunction(num);
|
|
break;
|
|
|
|
case 4: // Trigonometric
|
|
executeTrigonometricFunction(num);
|
|
break;
|
|
|
|
case 0: // Exit the loop
|
|
break;
|
|
|
|
default:
|
|
printf("Invalid choice. Please try again.\n");
|
|
}
|
|
}
|
|
|
|
|
|
// scientificMode
|
|
double scientificMode() {
|
|
double result;
|
|
int choice;
|
|
|
|
do {
|
|
double num = getNumberFromUser();
|
|
choice = getScientificModeChoice();
|
|
executeScientificFunction(num, choice);
|
|
} while (choice != 0);
|
|
|
|
return result;
|
|
}
|