Algorithm and Flowchart to Check whether a number is a Perfect Square

[477 views]


What are perfect square numbers?

A number is said to be a perfect square when the number is generated by multiplying two equal integers by each other. A perfect square can never be a negative integer because even if we multiply two negative integers, the product will always be positive.
For example: 1, 4, 9, 16, 25, 36, 121, 144, etc.

Let us take a look at the algorithm and flowchart to have a better understanding.

Algorithm to check whether a number is a Perfect Square:

Step 1. Start Step 2. Read the number to be checked from the user Step 3. If number >= 0: 3.1 Repeat for i=0 to number: 3.1.1: If number = (i*i): 3.1.2: Display “Perfect Square” 3.1.3: Stop 3.1.4: i = i + 1 3.2 Display “Not a Perfect Square” Step 4. Else: 4.1: Display “Not a Perfect Square” Step 5. Stop

Explanation:

The algorithm starts off by taking the number to be checked as user input. After that, we will check whether the number is greater than or equal to 0 or not, because a perfect square can never be a negative integer. If the number is positive, we will start a loop from zero to that number. For each value of the loop variable, we will check whether the square of that number and the given number are equal or not. If they are equal, the given number is a perfect square. So, the program will terminate here.

If the condition does not satisfy for any value of the loop variable, this means that the given number is not a perfect square.

Flowchart to check whether a number is a Perfect Square:

Flowchart to check whether a number is a Perfect Square
Remove WaterMark from Above Flowchart
        

Struggling to Understand Algorithm and Flowchart? Try our Notes



Want to Test Your Knowledge on Algorithm and Flowchart?



Comments



Search
Recommended Deals End in

Top Java Interview Questions PDF Guide with 30+ Pages



Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Quiz to Test Your Skills
Search Tags

    Perfect Square Number Validation Algorithm

    Perfect Square Number Validation Flowchart

    Pseudocode for checking Perfect Square Number