SquareRoot - double guess = 0.0 guess =(lower upper 2.0 if...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Comptuing square roots. Author: Eric Van Wyk Date: Feb 2, 2010 */ #include <iostream> using namespace std ; int main() { double lower = 0.0, upper = 0.0, n = 0.0, accuracy = 0.0 ; n = 16.0 ; accuracy = 0.001 ; lower = 1.0 ; upper = n ; // lower <= square-root(n) <= upper while ( (upper - lower) > accuracy ) { // lower <= square-root(n) <= upper
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: double guess = 0.0 ; guess = (lower + upper) / 2.0 ; if ( guess*guess > n ) upper = guess ; else lower = guess ; } // lower <= square-root(n) <= upper // and upper - lower <= accuracy cout << "The square root of " << n << " is between " << lower << " and " << upper << "." << endl ; }...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Ask a homework question - tutors are online