📄 no.5.c
字号:
#include "stdio.h"
#include "conio.h"
#define MIN -30000
#define ROOT_PRECISION 10e-5
float func1(float x, float a)
{
return (x*x*x - a);
}
float func1_1(float x, float a)
{
return (3*x*x);
}
float func2(float x, float c)
{
return (1 - c*x);
}
float func2_1(float x, float c)
{
return (-c);
}
float newton(float (*f)(float x, float a), float (*f_1)(float x, float c), float a, float x0)
{
float x, ox;
ox = x = x0;
do {
ox = x;
x = x - f(x, a) / f_1(x, a);
}while (x - ox > ROOT_PRECISION || ox - x > ROOT_PRECISION);
return ox;
}
int main()
{
float x;
x = newton(func1, func1_1, 10, MIN);
printf("%.5f\n", x);
x = newton(func2, func2_1, 0.324, 3);
printf("%.5f\n", x);
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -