Just starting to lean about algorithm and programming and professor gave us this question and told us to figure out what i does thanks for the help
Code:#include <cstdlib> #include <iostream> #include <cmath> using namespace std; int main( ) { double a, x_old, x_new; cout << "Enter a positive DECIMAL number => "; cin >> a; x_old = 1; x_new = 0.5*( 1 + a ); while( fabs(x_old - x_new) >= 0.00005) { x_old = x_new; x_new = 0.5*( x_old * x_old + a )/x_old; } cout << "\nThe value that you are seeking is " << x_new << endl; cout << "Press the enter key to continue ..."; cin.get(); return 0; }




Reply With Quote