Search code examples
pseudocode

Is the pseudo code written below correct for the question (write a pseudocode to find out if the given number is a prime number)?


Is the pseudo code written below correct for the question

Input a number

X = number - 1
If X mod 2 = 0 then
    Print number, “is not a prime number”
Else
    Print number, “is a prime number”

Solution

  • No. You are just lowering the entered number by one and check if it is divisible by 2.

    Basically, you would have to do something like this:

    • take a variable (let's say x) and set it to 2
    • while the input mod x is not zero and x is smaller than half of input do:
    • add one to x
    • if there was never input mod x = zero then input is a prime

    Beware that this is not optimized at all, but the concept is correct.