?? 7-8.c
字號:
/*牛頓迭代法*/
#include<stdio.h>
#include<math.h>
float solut(float a,float b,float c,float d)
{
float x=1,x0,f,f1;
do
{
x0=x;
f=((a*x0+b)+c)*x0+d;
f1=(3*a*x0+2*b)*x0+c;
x=x0-f/f1;
}
while(fabs(x-x0)>=0.00001);
return (x);
}
main()
{
float a,b,c,d;
printf("\n Input a,b,c,d=\n");
scanf("%f,%f,%f,%f",&a,&b,&c,&d);
printf("Equation is %5.2fX^3+%5.2fX^2+%5.2fX+%5.2f=0",a,b,c,d);
printf("\n x=%10.7f\n",solut(a,b,c,d));
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -