?? newton.cpp
字號(hào):
// diedai.cpp : Defines the entry point for the console application.
//
//第104頁24題:用牛頓法求方程的根
#include "stdafx.h"
#include "iostream.h"
#include "math.h"
float fun(float x)
{
float m;
m=x-(x*x*x+2*x*x+10*x-20)/(2*x*x+4*x+10);
return m;
}
int main(int argc, char* argv[])
{
int k=0,N;
float x0,x1;
x0=1.0;
cout<<"求方程x*x*x+2*x*x+10*x-20=0的根"<<endl;
cout<<"輸入需要迭代的次數(shù):";
cin>>N;
for(;k<=N;k++)
{
x1=fun(x0);
if(fabs(x1-x0)<0.000001)
break;
x0=x1;
}
cout<<"求出的根為x="<<x1<<endl;
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -