fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. double x;
  5. int n;
  6. scanf("%lf %d", &x, &n);
  7.  
  8. int fact = 1;
  9. double ans = 0, deg = x;
  10. for (int i = 1; i <= n * 2 - 1; i += 2) {
  11. double c = deg / fact;
  12. if ((i / 2) % 2 == 0) {
  13. ans += c;
  14. } else {
  15. ans -= c;
  16. }
  17. fact *= (i + 1);
  18. fact *= (i + 2);
  19. deg *= x * x;
  20. }
  21.  
  22. printf("%.6f", ans);
  23. return 0;
  24. }
Success #stdin #stdout 0s 5324KB
stdin
3.1415 1
stdout
3.141500