#include <stdio.h>

double factorial(int n) {
    if (n <= 1) {
        return 1;
    } else {
        return n * factorial(n - 1);
    }
}

int main() {
    double x = 1, term = 1;
    int i = 1;
    while (term >= 1e-5) {
        term = 1.0 / factorial(i);
        if (i % 2 == 1) {
            x -= term;
        } else {
            x += term;
        }
        i++;
    }
    printf("x = %lf\n", x);
    return 0;
}
编程C语言程序计算x=1-12+14!-…要求精度为1e-5

原文地址: https://www.cveoy.top/t/topic/bZeW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录