Ask Question
3 December, 12:33

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)

+5
Answers (1)
  1. 3 December, 16:15
    0
    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers