/*********************************************************************************
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 third_root(double x, double guess);
int main()
{
cout<<"square_root = " <<third_root(2, 1.5)<<endl;
while(1);
return 0;
}
static double third_root(double x, double guess)
{
double new_guess = (x/(guess*guess) + 2 * guess) / 3;
if(fabs(new_guess - guess) < 0.00001)
{
return new_guess;
}else
{
return third_root(x, new_guess);
}
}
递归练习之求立方根
最新推荐文章于 2021-10-10 20:40:34 发布