fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. double x, resultado;
  6. int N, n;
  7.  
  8. resultado = 0.0;
  9.  
  10. scanf("%lf", &x);
  11. scanf("%d", &N);
  12.  
  13. for (n = 0; n <= N; n++) {
  14. double termo = pow(-1, n) * pow(x, 2 * n) / (tgamma(2 * n + 1));
  15. resultado += termo;
  16. }
  17.  
  18. printf("cos(x) = %.2f\n", x);
  19. printf("cos(x) = %.6f\n", resultado);
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0.01s 5296KB
stdin
2
9
stdout
cos(x) = 2.00
cos(x) = -0.416147