fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5. //for6
  6. //float x;
  7. //cin >> x;
  8. //for (float i = 1.2; i < 2.1; i += 0.2) {
  9. // cout << i * x << endl;
  10. //}
  11. //for26
  12. double x;
  13. int n;
  14. cin >> x >> n;
  15. double result = 0;
  16. long factorial = 1;
  17. double current_x = x;
  18. for (int i = 1; i <= 2 * n + 1; i += 2) {
  19. result += current_x / factorial;
  20. factorial *= (i + 1) * (i + 2);
  21. current_x *= -x * x;
  22. }
  23. cout << result;
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5316KB
stdin
2 2
stdout
0.933333