fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7. double x, elem, sum = 0, delta;
  8. cin >> x >> delta;
  9. double si = sin(x), rs = 1 + delta;
  10. elem = x;
  11. for (int i = 1; rs > delta; i++)
  12. {
  13. sum += elem;
  14. elem *= (-1) * x * x / (2 * i)/(2 * i + 1);
  15. rs = fabs( si - sum);
  16. }
  17. cout << " x = ";
  18. cout << " sin(" << x << ") = "<< sum << endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 3476KB
stdin
2.09 0.0001
stdout
 x =  sin(2.09) = 0.868296