Quick actions

cmd+k|ctrl+k

Navigation

Languages

WenhaoCui_6153876930_HW1_Q1

Snippet info

Language

Cpp

Visibility

public

Author

chriscui14

Created

2020-05-28T04:24:18Z

Updated

2020-05-28T04:26:05Z

#include <iostream>
#include <cmath>
using namespace std;
double mySqrt(double x){
    double estimate = 1;
    double newEstimate = 0.5*(estimate + x/estimate);
    while (abs(newEstimate-estimate)>0.000001){
        estimate = newEstimate;
        newEstimate = 0.5*(estimate + x/estimate);
    }
    return estimate;
}

int main() {
    double s = mySqrt(5); 
    cout << s << endl; // expect 2.236
    return 0;
}
INFO