C++ Use the code: #include <iostream> using namespace std; /* Type your code her
ID: 3857634 • Letter: C
Question
C++
Use the code:
#include <iostream>
using namespace std;
/* Type your code here. */
int main()
{
int num;
cout << "Please enter a number between 2 and 1000: ";
cin >> num;
cout << num << endl;
if ((num < 1) || (num > 1000))
cout << "Please follow the directions!" << endl;
else {
int answer;
answer = intSqrRoot(num);
cout << "The integer square root of ";
cout << num;
cout << " is ";
cout << answer;
cout << ".";
cout << endl;
}
}
Explanation / Answer
#include <iostream>
using namespace std;
/* Type your code here. */
int intSqrRoot(int num)
{
int square = 1 * 1;// Start with 1
int count = 1;// Counter increment with each iteration
cout << "[" << count << "]";// Intermediate numbers
while (square <= num)//run until square is greater than number
{
if (square < num)
{
cout << "[" << count << "]";// Intermediate numbers
}
count++;//Increment counter
square = count * count;//update square of counter
}
cout << " ";
return count - 1;//return previous counter
}
int main()
{
int num;
cout << "Please enter a number between 2 and 1000: ";
cin >> num;
// cout << num << endl;
if ((num < 1) || (num > 1000))
cout << "Please follow the directions!" << endl;
else {
int answer;
answer = intSqrRoot(num);
cout << "The integer square root of ";
cout << num;
cout << " is ";
cout << answer;
cout << ".";
cout << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.