游客 Signup | Login
中文 | En

1173 - C语言6.21

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

Input

Output

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

请注意行尾输出换行。

Examples

Input

Output

2.0000

Solution 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;
}

Solution 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;
}

Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题