1173 - C语言6.21

用牛顿迭代法求以下方程在1.5附近的根:

题目输入

题目输出

输出牛顿迭代法求出的根,保留4位小数。

请注意行尾输出换行。

输入/输出样例

题目输入

题目输出

2.0000

C语言解答

#include <stdio.h>
#include <math.h>
int main() {
        float x;
        x = 1.5;
        while (fabs(2 * x * x * x - 4 * x * x + 3 * x - 6) > 1e-6) {
                x = x - (2 * x * x * x - 4 * x * x + 3 * x - 6) / (6 * x * x - 8 * x + 3);
        }
        printf("%.4f\n", x);
        return 0;
}

C++解答

#include <stdio.h>
#include <math.h>
int main() {
	float x;
	x = 1.5;
	while (fabs(2 * x * x * x - 4 * x * x + 3 * x - 6) > 1e-6) {
		x = x - (2 * x * x * x - 4 * x * x + 3 * x - 6) / (6 * x * x - 8 * x + 3);
	}
	printf("%.4f\n", x);
	return 0;
}

时间限制 1 秒
内存限制 32 MB
讨论 统计
上一题 下一题