Ask Question
2 July, 21:03

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 July, 00:40
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers