求公式近似值formula.c 474 B

12345678910111213141516171819202122232425262728
  1. #include <stdio.h>
  2. double calculateFactorial(int n) {
  3. if (n == 0) {
  4. return 1;
  5. } else {
  6. return n * calculateFactorial(n - 1);
  7. }
  8. }
  9. int main() {
  10. double x, result = 1.0;
  11. int n;
  12. scanf("%lf %d", &x, &n);
  13. int i,j;
  14. for (i = 1; i <= n; i++) {
  15. double term = 1.0;
  16. for (j = 1; j <= i; j++) {
  17. term *= x / j;
  18. }
  19. result += term;
  20. }
  21. printf("%.6f\n", result);
  22. return 0;
  23. }