/* Approximate a solution to f(x)=0 using 5 iterations of Newton's method with an initial guess of x0. Note: If you change f you must also change df below. */ #include #include double answer[]={ 3.00000000000000e+00, 2.33333333333333e+00, 2.23809523809524e+00, 2.23606889564336e+00, 2.23606797749998e+00 }; double f(double x){ return x*x-5; } double df(double x){ return 2*x; } double g(double x){ /* Please fill in this function */ } int main(){ printf("This is problem 3 on quiz 2.\n"); int flag=0; double x=1; for(int n=0;n<5;n++){ x=g(x); printf("n=%d x_n=%.14e ",n+1,x); if(fabs(x-answer[n])<1e-11) printf(" ...okay!\n"); else printf(" ...wrong.\n"),flag++; } if(!flag){ printf("Congratulations! Your answer is correct!\n"); } else { printf("Please try again. Your answer is incorrect.\n"); } return 0; }