2024-10-09 17:02:42 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int sqrt(int number) {
|
|
|
|
int initialGuess = 2;
|
|
|
|
|
|
|
|
while (abs(initialGuess - number / initialGuess) > 1) {
|
|
|
|
initialGuess = (initialGuess + number / initialGuess) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return initialGuess;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2024-10-09 17:02:43 +00:00
|
|
|
std::cout << "Type a number to predict the square root of: ";
|
2024-10-09 17:02:42 +00:00
|
|
|
|
|
|
|
int number;
|
2024-10-09 17:02:43 +00:00
|
|
|
std::cin >> number;
|
2024-10-09 17:02:42 +00:00
|
|
|
|
2024-10-09 17:02:43 +00:00
|
|
|
std::cout << sqrt(number);
|
2024-10-09 17:02:42 +00:00
|
|
|
}
|