You recall an algorithm from elementary school for factoring a number N: Divide out all factors of 2, then of 3, then of 4, then of 5, then of 6, then of 7, etc. Finally, divide out all factors of N (of which there can be at most one). (a) Write pseudo-code for this algorithm (and print the prime factors)

Respuesta :

Answer:

let number = 0

while number < 1

  begin

     print "Enter a positive integer: "

     read number

  end

end_while

find and print number's factors:

let prime = TRUE

let currentFactor = 2

let lastFactor = the square root of number truncated

  to an integer value

while currentFactor <= lastFactor

  begin

     if number is evenly divisible by currentFactor

        begin

           print currentFactor

           let number = number / currentFactor

        end

     else

        let currentFactor = currentFactor + 1

     end_if

  end

end_while

print a message if number is prime:

if prime == TRUE

  print "Your number is prime"

end_if

Explanation: