Answer:
START
PROMPT "Enter a number: "
GET number
IF number < 2 THEN
DISPLAY "This is not a prime number."
STOP
ELSE
SET is_prime = True
SET divisor = 2
WHILE divisor < number
IF number MOD divisor = 0 THEN
SET is_prime = False
BREAK
END IF
SET divisor = divisor + 1
END WHILE
IF is_prime THEN
DISPLAY "This is a prime number."
ELSE
DISPLAY "This is not a prime number."
END IF
END IF
STOP
Step-by-step explanation:
Here is a breakdown of what this Flowgorithm diagram does:
- Prompt the user to enter a number.
- Read in the number.
- If the number is less than 2, it is not a prime number, so the program displays a message and stops.
- If the number is greater than or equal to 2, the program sets a variable is_prime to True and sets a variable divisor to 2.
- The program enters a while loop that will run as long as divisor is less than number.
- Inside the loop, the program checks if number is evenly divisible by divisor using the modulus operator (%). If it is, the program sets is_prime to False and exits the loop using the break statement.
- If number is not evenly divisible by divisor, the program increments divisor by 1 and the loop continues.
- When the loop ends, the program checks the value of is_prime. If it is True, the program displays a message saying that the number is a prime number. If it is False, the program displays a message saying that the number is not a prime number.
I hope this helps! Let me know if you have any questions.