Question:

Prime Numbers Exercise:  (Pseudo code and Flowchart).

A prime number is a number that is only evenly divisible by itself and 1.
For example, the number 5 is prime because it can only be evenly divided by 1 and 5.
The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6.

Design a Boolean function named isPrime which takes an integer as an argument and returns True if the argument is a prime number, or False otherwise.
Use the function in a program that prompts the user to enter a number and then displays a message indicating whether the number is prime.

Solution:
Pseudo code

Function main
//No arguments passed to main function
Pass In: nothing

                //Declare variables
Declare Integer number
Declare Boolean result

                //Get the number
Display “Enter an integer number”
Input number

                //value returned by call to isPrime (number) function assigned to result
result = Call: isPrime Pass In number

                If result is equal to True Then
Display “number is prime”
Else
Display “number is non prime”
End if

                //nothing (value zero) is returned by main to operating system
Pass Out: value zero to the operating system
End function

Function isPrime
//number is argument in this function
Pass In: integer number

//Declare variables
Declare Integer count
Declare Boolean prime

count = two
prime = True

//while loop
While count <= number/2
If number mod count is equal to zero
prime = False
End if
Increment count
End while

//prime is returned by this function
Pass Out: prime
End function