Unformatted text preview: guess = rand() / static_cast<double>(RAND_MAX) ; // scale to range [0, (upper-lower)] guess = guess * (upper - lower) ; // move to range [lower, upper] guess = guess + lower ; cout << "Guess is " << guess << endl ; 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
- Spring '08
- Complex number, Imaginary unit, Square number