标签:class code color int strong string
立方根的逼近迭代方程是 y(n+1) = y(n)*2/3 + x/(3*y(n)*y(n)),其中y0=x.求给定的x经过n次迭代后立方根的值。
输入有多组数据。
每组一行,输入x n。
迭代n次后的立方根,double精度,保留小数点后面六位。
3000000 28
144.224957
#include
"stdio.h"int
main(int argc, char* argv[]){ long n; double x; while(scanf("%lf%d",&x,&n)!=EOF){ double temp=x; while(n>0){ x = x*2/3 + temp/(3*x*x); // y(n+1) = y(n)*2/3 + x/(3*y(n)*y(n)) n--; } printf("%.6lf\n",x); } return 0;}考察数据类型的掌握---题目1166:迭代求立方根 (2009年北京航空航天大学计算机研究生机试真题),布布扣,bubuko.com
考察数据类型的掌握---题目1166:迭代求立方根 (2009年北京航空航天大学计算机研究生机试真题)
标签:class code color int strong string
原文地址:http://www.cnblogs.com/Murcielago/p/3704598.html