标签:des blog io ar os sp on 2014 log
/********************************************************************************* Copyright (C), 1988-1999, drvivermonkey. Co., Ltd. File name: Author: Driver Monkey Version: Mail:bookworepeng@hotmail.com qq:196568501 Date: 2014.04.02 Description: 递归练习之求平方根 *********************************************************************************/ #include <iostream> #include <sstream> #include <fstream> #include <iostream> #include <iomanip> #include <string> #include <memory.h> #include <thread> #include <stdlib.h> /* labs */ #include <math.h> using namespace std; static double square_root(double x, double guess); static double average(double value1, double value2); int main() { cout<<"square_root = " <<square_root(2, 1.5)<<endl; while(1); return 0; } static double square_root(double x, double guess) { double quotient = x / guess; double average_value = average(quotient, guess); if(fabs(average_value -guess) < 0.000000000000000001L) { return guess; }else { return square_root(x, average_value); } } static double average(double value1, double value2) { return (value1 + value2) / 2; }
标签:des blog io ar os sp on 2014 log
原文地址:http://blog.csdn.net/drivermonkey/article/details/41457273