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(%.2lf) = %.6lf\n", x, resultado);
  19.  
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0.01s 5304KB
stdin
2
9
stdout
cos(2.00) = -0.416147