Ask Question
3 March, 16:49

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)

+1
Answers (1)
  1. 3 March, 16:54
    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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers