#include <iostream> #include<cmath> using namespace std; float f(float x) { return x*x*x+2*x*x+x-1; } float f1(float x) { return 1/((x+1)*(x+1)); } void jieguo() { float m,n, a,b,c=4,x; int k=0; cout<<"请输入迭代初值a和有效数字位数c:"<<endl; cin>>a>>c; m=a; while(1) { cout<<k<<" "<<m<<endl; n=f1(m); if(fabs(m-n)<=0.5*pow(10,-c)) { cout<<m<<" "<<n<<endl; cout<<n<<endl; break; } m=n; k++; } } int main() { jieguo(); }