求公式近似值.c 460 B

12345678910111213141516171819202122232425
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main() {
  4. int n, num = 1;
  5. double x, ex = 1;
  6. scanf("%lf %d", &x, &n);
  7. while (num <= n) {
  8. double factorial = 1;
  9. int factorialnum = 1;
  10. while (factorialnum <= num) {
  11. factorial *= factorialnum;
  12. factorialnum += 1;
  13. }
  14. ex += pow(x, num) / factorial;
  15. num += 1;
  16. }
  17. printf("%.6lf", ex);
  18. return 0;
  19. }