Here is the problem: Ask the user for a number between 2 and 1000. Calculate the integer square root by calculating the square of every number from 1 until the square of the number is more than the number entered. The previous number is the integer square root. For example, if the user enters 15, your program would calculate 1x1 = 1, 2x2 = 4, 3x3 = 9, 4x4 = 16 -- since 16 is too high, the integer square root of 15 is 3
int number = 0;
int squares = 0;
std::cout << "Enter a number " << std::endl;
std::cin >> number;
for ( ;; ++squares )
{
if ( squares * squares > number )
{
std::cout << squares*squares << " is too high the square root of " << number << " is " << squares - 1 << std::endl;
break;
}
}
#include <iostream>
int main() {
std::cout << "Enter a number between 2 and 1000" << std::endl;
int x;
std::cin >> x;
if (x >= 2 && x <= 1000) {
for (int i = 1; i <= 31; ++i){
std::cout << i << " x " << i << " is " << i*i << std::endl;
if (((i*i) < x) && (((i+1)*(i+1)) > x)){
std::cout << "The integer square root of " << x << " is " << i << std::endl;
return 0;
}
}
}
else {
std::cout << "Number must be between 2 and 1000!" << std::endl;
return -1;
}
}