// Program to find the square root of a number #include #include #include using namespace std; const int MAXTIMES = 50; const double EPSILON = 1.0e-012; int main () { double trialx; // Trial square root double nextTrial; // Next trial root double number; // Number to take sq. root of double diff = 1.0; // Change in root value int count = 1; // Loop count // Get starting values cout << "Number to take square root of: "; cin >> number; cout << endl << "Using Newton's Method" << endl << "Initial" << " trial for root: "; cin >> trialx; nextTrial = 0.5 * (trialx + number / trialx); // Start table for output cout << "Count Trial root of " << number << endl; cout << scientific << showpoint; while (count < MAXTIMES && fabs(diff) > EPSILON) { diff = trialx - nextTrial; cout << setw(5) << count << setprecision(12) << setw(22) << trialx << endl; // Get next estimate trialx = nextTrial; nextTrial = 0.5*(trialx+number / trialx); count++; } cout << setw(5) << count <