fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. double sinus( double x, int precision = 10 )
  7. {
  8. double wynik = 0;
  9. double y = x;
  10. double z = 2;
  11.  
  12. for ( int n = 0; n < precision; ++n )
  13. {
  14. wynik += y;
  15. y *= -x * x;
  16. y = y / ( z++ );
  17. y = y / ( z++ );
  18. }
  19.  
  20. return wynik;
  21. }
  22.  
  23. inline double deg_to_rad( double degrees )
  24. {
  25. return degrees * 0.01745329251994329577; // degrees * pi / 180
  26. }
  27.  
  28. int main()
  29. {
  30. cout << setprecision(20);
  31. cout << sinus( deg_to_rad( 35.0 ) ) << endl; // 0.57357643635104609611
  32. cout << sinus( deg_to_rad( 50.0 ), 100 ) << endl; // 0.7660444431189780352
  33. cout << sinus( deg_to_rad( 45.0 ), 200 ) << endl; // 0.7071067811865475244
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
0.5735764363510460484
0.76604444311897779141
0.70710678118654746172