求cosx的值:根据以下公式求cosx的近似值,要求累加到某项的绝对值小于1e-6时为止。

在这里插入图片描述

#include <stdio.h>
#include <math.h>

void main() {
    double x, t, s = 0;
    int i = 0;
    scanf("%lf", &x);
    t = 1;
    while (fabs(t) >= 1e-6) {
        s += t;
        i++;
        t = -t * x * x / (2 * i) / (2 * i - 1);
    }
    printf("%.2lf", s);
}
发布了139 篇原创文章 · 获赞 4 · 访问量 93万+

猜你喜欢

转载自blog.csdn.net/qq_38490457/article/details/104738300