Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double radians(double degrees) // converts degrees to radians
  7. {
  8. double radians;
  9. double const pi = 3.14159265358979323846;
  10. radians = (pi / 180) * degrees;
  11. return radians;
  12. }
  13.  
  14. double fact(int x) //calculates the factorial
  15. {
  16. double fact = 1;
  17. for (; x >= 1; x--) {
  18. fact = x * fact;
  19. }
  20. return fact;
  21. }
  22.  
  23. double sin(double x) {
  24. double sum = 0;
  25. int i = 1;
  26. int sign = 1;
  27. double term;
  28. do {
  29. term = pow(x, i) / fact(i);
  30. sum += sign * term;
  31. sign = -sign;
  32. i += 2;
  33. } while (term > 0.000001);
  34.  
  35. return sum;
  36. }
  37.  
  38.  
  39. int main() {
  40. double n, output;
  41. cout << "Please enter the value in degrees: ";
  42. cin >> n;
  43.  
  44. n = radians(n);
  45. cout << "The angle in radians is: " << n << endl;
  46.  
  47. output = sin(n);
  48.  
  49. cout << "The sinus is: " << output << endl;
  50.  
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement