Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5.  
  6. double intoRadians(double fdegree);
  7.  
  8. double trygonometric_calc(double fdegree, int func_choiсe);
  9.  
  10.  
  11. int main()
  12. {
  13. int func_choice;
  14. double degree;
  15.  
  16. puts("Choice the function to calculate(1 - sin, 2 - cos, 3 - tan, 4 - cot):");
  17. // Почитай почему %u
  18. scanf("%u", &func_choice);
  19.  
  20. puts("Enter the degree:");
  21. scanf("%lf", &degree);
  22.  
  23. printf("Result: %lf", trygonometric_calc(degree, func_choice));
  24.  
  25. system("pause");
  26.  
  27. return 0;
  28. }
  29.  
  30. double intoRadians(double fdegree)
  31. {
  32. return (fdegree * 3.14) / 180;
  33. }
  34.  
  35. double trygonometric_calc(double fdegree, int func_choice)
  36. {
  37. if ( (func_choice > 4) || (func_choice < 1))
  38. {
  39. puts("Invalid input");
  40. exit(0);
  41. }
  42.  
  43. switch (func_choice)
  44. {
  45. case 1:
  46. return sin(intoRadians(fdegree));
  47.  
  48. case 2:
  49. return cos(intoRadians(fdegree));
  50.  
  51. case 3:
  52. return tan(intoRadians(fdegree));
  53.  
  54. case 4:
  55. return 1 / tan(intoRadians(fdegree));
  56.  
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement