The following program prints the number of squares present between two numbers.The program is implemented using C++ language.

Ex:

Let the two numbers be 3 and 9.

There are two squares between them i.e. 4 and 9.So the output will be 2.

Ex:

Let the two numbers be 3 and 9.

There are two squares between them i.e. 4 and 9.So the output will be 2.

#include<iostream>

#include<math.h>

using namespace std;

int main()

{

int x,y;

cout<<"Enter two elements : "<<endl;

cin>>x>>y;

x=sqrt(x-1);

y=sqrt(y);

cout<<"nThe number of squares present : "<<(y-x);

return 0;

}

### Description :

In the above program let the two elements be A and B. x is the square root of A and y is the square root of B. The squares of x and y lies in between A and B. Therefore square of elements present between x and y are also present in the range of A and b.

### Ex:

5 and 20 are two elements for the program.

x=sqrt(5-1)=2 and y=sqrt(20)=4

According to program the count will be 2.9 and 16 are only two square elements present between 5 and 20.

#### Output:

#### Case 1:

Enter two elements :

3 9

The number of squares present : 2

#### Case 2:

Enter two elements :

15 24

The number of squares present : 1

#### Case 3:

Enter two elements :

25 49

The number of squares present : 3

### Bikash Panda

Blogger / Embedded System Developer at WeArGenius

A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.

#### Latest posts by Bikash Panda (see all)

- OSMC on Raspberry PI with Setup and Control using Android App - July 7, 2017
- DHT12 Interfacing with Raspberry Pi using Pi4J - June 19, 2017
- Send data using MQTT from Raspberry Pi with JAVA - June 12, 2017

## Leave a Reply