  # In C++Create a function called checkSquares. It should take in two numbers bottom and top. It should output to the console any numbers in the range from bottom to top that are perfect squares. So if you take in 5 to 20 it should output 9 and 16 to the console.

Question

In C++

Create a function called checkSquares. It should take in two numbers bottom and top. It should output to the console any numbers in the range from bottom to top that are perfect squares. So if you take in 5 to 20 it should output 9 and 16 to the console.

check_circleExpert Solution
Step 1

The checkSquares function is created in C++ that will take two numbers as a bottom number and a top number and will produce the perfect squares within the range of those two numbers.

Step 2

The following C++ program will print the perfect squares within the given range of numbers.

#include <bits/stdc++.h>

using namespace std;

int checkSquares(int a, int b)

{

// check through all numbers

for (int i = a; i <= b; i++)

// Check whether the current number 'i' is a perfect square

for (int j = 1; j * j <= i; j++)

if (j * j == i)

cout<<j*j<<"\n";    // print the perfect squares

}

// Main code

int main()

{

int a = 5, b = 20;

cout << "Perfect squares in the given range are:\n ";

checkSquares(a, b);

return 0;

}

Step 3

In the given program, checkSquares function is defined firstly. Within the function definition part, all the numbers are traversed to check whether the number is a perfect square or not. If it is a perfect...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

### Computer Science 