Search for question
Question

Goal: Determine if a number is prime or not. A prime number is divisible only by 1 and itself.

5 is a prime number.

How do I know that?

Between 1 and 5, 5 is divisible only by 1 and 5 and no other number.

18 is not a prime number.

How do I know that?

Between the numbers 1 and 18, 18 is divisible by the numbers 1, 2, 3, 6,

9, 18

so it is not prime.

Logic

By counting how many numbers can divide the number "n" between 2 and n-

1, I can decide if a number is prime or not. If the count is zero, the

number is prime. Else it is not prime

For example, if n = 5, I check if 5 can be divided by 2 or 3 or 4 (n-1 ie 5-1)

Steps

1. Write a prompt to ask the user to enter a whole number

Enter a number :

2. Read the input, convert to whole number and save to variable "num". "num" should store whole

numbers.

3. Start a loop using "counter" starting from 2 to n-1. Increment counter by 1

4. Declare a variable called "remainder" and set it to 0. It should be able to store whole numbers

Fig: 1