text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

c01p062c.cpp

Go to the documentation of this file.
00001 
00015 // Computes and writes floor(sqrt(x)) for
00016 // an input value x >= 0.
00017 
00018 int main()
00019 {
00020    int x;  // input value
00021 
00022    // initialize
00023    int result = 0;  // will equal floor of sqrt(x)
00024    int temp1 = 1;
00025    int temp2 = 1;
00026 
00027    cin >> x;        // read input
00028 
00029    // compute floor
00030    while (temp1 < x)
00031    {  ++result;
00032       temp2 += 2;
00033       temp1 += temp2;
00034    }  // end while
00035 
00036    cout << "The floor of the square root of "
00037    << x << " is " << result << endl;
00038    return 0;
00039 }  // end main

Generated on Sat Aug 26 19:58:10 2006 for AWLogo by  doxygen 1.4.6