C++ program to check whether a number is complete square or not

This program inputs a positive integer from user, checks whether it is a complete square or not and outputs the result to the user.


We use three variables in this program. n is used to store the number under check which is input by the user. i is initialized from 0 and then incremented by one during the execusion of a while loop. m is used to store the square of i during each loop. The loop executes as long as square of i i. e m is less than the number n. After this loop, an if selection statement is used to check whether this square which we have obtained as a result of execution of this loop is equal to the number n or not? if, it is, then we tell the user that the number he entered is a complete square. Otherwise we display a message on the screen stating that this number is not a complete square.

If you have any suggestions to improve this program then please let me know them via comments. I shall be very thankful to you!

Source Code:

Leave a Reply