Advertisement
roneygomes

aproximator

Sep 2nd, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int number;
  8.    
  9.     cout << "Insert a natural number: ";
  10.     cin >> number;
  11.    
  12.     float root = sqrt(number);
  13.    
  14.     if((ceil(root) - root) > (root - floor(root)))
  15.         cout << floor(root) << endl;
  16.     else if((ceil(root) - root) < (root - floor(root)))
  17.         cout << ceil(root) << endl;
  18.     else
  19.         cout << ceil(root) << endl;
  20.        
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement