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

  1. // scientificMode
  2. #include <stdio.h>
  3. #include <math.h>
  4. // get the number which has to be calculated
  5. double getNumberFromUser() {
  6. double num;
  7. printf("Enter a number: ");
  8. scanf("%lf", &num);
  9. return num;
  10. }
  11. // Choice for ScientificMode
  12. int getScientificModeChoice() {
  13. int choice;
  14. printf("Scientific mode Options:\n");
  15. printf("1: Square root\n");
  16. printf("2: Exponential\n");
  17. printf("3: Logarithm\n");
  18. printf("4: Trigonometric\n");
  19. printf("0: Exit\n");
  20. scanf("%d", &choice);
  21. return choice;
  22. }
  23. // Choice for Logarithm
  24. int getLogarithmChoice() {
  25. int logChoice;
  26. printf("Logarithm Options:\n");
  27. printf("1: Logarithm (base 10)\n");
  28. printf("2: Natural Logarithm (ln)\n");
  29. printf("3: Logarithm (base 2)\n");
  30. printf("0: Exit Logarithm Menu\n");
  31. scanf("%d", &logChoice);
  32. return logChoice;
  33. }
  34. // Choice for Trigonomtri
  35. int getTrigonometricChoice() {
  36. int trigChoice;
  37. printf("Trigonometric functions:\n");
  38. printf("1: Sine\n");
  39. printf("2: Cosine\n");
  40. printf("3: Tangent\n");
  41. printf("0: Exit Trigonometric Menu\n");
  42. scanf("%d", &trigChoice);
  43. return trigChoice;
  44. }
  45. // Logarithm
  46. void executeLogarithmFunction(double num) {
  47. int logChoice;
  48. do {
  49. logChoice = getLogarithmChoice();
  50. switch (logChoice) {
  51. case 1: // Logarithm (base 10)
  52. printf("Result: %lf\n", logarithmFunction(num));
  53. break;
  54. case 2: // Natural Logarithm (ln)
  55. printf("Result: %lf\n", naturalLogarithmFunction(num));
  56. break;
  57. case 3: // Logarithm (base 2)
  58. printf("Result: %lf\n", logarithmBase2Function(num));
  59. break;
  60. case 0: // Exit the logarithm menu
  61. break;
  62. default:
  63. printf("Invalid logarithm function choice. Please try again.\n");
  64. }
  65. } while (logChoice != 0);
  66. }
  67. // Trigonometric
  68. void executeTrigonometricFunction(double num) {
  69. int trigChoice;
  70. do {
  71. trigChoice = getTrigonometricChoice();
  72. switch (trigChoice) {
  73. case 1: // Sine
  74. printf("Result: %lf\n", sineFunction(num));
  75. break;
  76. case 2: // Cosine
  77. printf("Result: %lf\n", cosineFunction(num));
  78. break;
  79. case 3: // Tangent
  80. printf("Result: %lf\n", tangentFunction(num));
  81. break;
  82. case 0: // Exit the trigonometric menu
  83. break;
  84. default:
  85. printf("Invalid trigonometric function choice. Please try again.\n");
  86. }
  87. } while (trigChoice != 0);
  88. }
  89. void executeScientificFunction(double num, int choice) {
  90. double result;
  91. switch (choice) {
  92. case 1: // Square root
  93. result = squareRootFunction(num);
  94. printf("Result: %lf\n", result);
  95. break;
  96. case 2: // Exponential
  97. result = exponentialFunction(num);
  98. printf("Result: %lf\n", result);
  99. break;
  100. case 3: // Logarithm
  101. executeLogarithmFunction(num);
  102. break;
  103. case 4: // Trigonometric
  104. executeTrigonometricFunction(num);
  105. break;
  106. case 0: // Exit the loop
  107. break;
  108. default:
  109. printf("Invalid choice. Please try again.\n");
  110. }
  111. }
  112. // scientificMode
  113. double scientificMode() {
  114. double result;
  115. int choice;
  116. do {
  117. double num = getNumberFromUser();
  118. choice = getScientificModeChoice();
  119. executeScientificFunction(num, choice);
  120. } while (choice != 0);
  121. return result;
  122. }