HW1

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std;
#include <iostream> #include <cmath> using namespace std; double mySqrt(double n){ double estimate=1; double newEstimate= 0.5*(estimate + n/estimate); if ((estimate*estimate)==n) { // check if n=1 basically return n; } while (abs(estimate-newEstimate)>0.000001){ estimate=newEstimate; newEstimate= 0.5*(estimate + n/estimate); } return estimate; } int main() { double s = mySqrt(5); cout << s << endl; // expect 2.236 return 0; }// main()
Editor Settings
Theme
Key bindings
Full width
Lines