Asked Sep 9, 2019

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

Check out a sample Q&A here.

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

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add

Q: Create a list of 3 technologies that have gone from analog to digital. What was the reasoning for e...

A: Back in 1970s and earlier main technology in use was analog technology. Analog technology used vario...


Q: Visual Basic. Write an expression that evaluates to true if the value of the integer variable number...

A: In visual basic we use the Mod operator to check the remainder of a division.


Q: how to write a function that takes an integer n and prints all of the integers between 1 and n which...

A: Since no programming language is specified we choose python as it is one of most popular programming...


Q: For problem 10RQ for Business Informaiton Systems book by Paige Baltzan, the question asked what is ...

A: The terms Collective intelligence, Knowledge management and Crowdsourcing are related to each other ...


Q: You need to use Eclipse to create this program.

A: Instructions for the first program:Create an array of size 5 and initialize a counter variable named...


Q: I need help with creating a main.css, I already have the HTML.the details are in the pic and I will ...

A: CSS codebody{font-family: Sans-serif;/*set the font to Sans serif*/} a {color: maroon;/*set links to...


Q: How do I define a recursive function with C++? I am supposed to compute the Fibonacci numbers with a...

A: The algorithm for the recursive Fibonacci series is as below:Start with the first element which is 0...


Q: Find all strings in L ((a + bb)∗) of length five.

A: Answer:The symbol “+”denoted as “OR” operator which means “a + b” means either “a” or “b”, so the la...


Q: function myCompose(f,g){// TODO: return (f o g);// that is, a function that returns f(g(x)) wh...

A: Click to see the answer