2022-01-15 19:36:30 +00:00
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int sqrt(int number) {
|
|
|
|
int initialGuess = 2;
|
|
|
|
|
|
|
|
while (abs(initialGuess - number / initialGuess) > 1) {
|
|
|
|
initialGuess = (initialGuess + number / initialGuess) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return initialGuess;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2022-01-15 22:33:46 +00:00
|
|
|
cout << "Type a number to predict the square root of: ";
|
2022-01-15 19:36:30 +00:00
|
|
|
|
|
|
|
int number;
|
|
|
|
cin >> number;
|
|
|
|
|
|
|
|
cout << sqrt(number);
|
|
|
|
}
|