### recursion question

I really need help with this and a sarcastic comment is not what I consider help, so if you can please give me a hand with this. Any help is appreciated, thanks in advance.

I was assigned a homework where I have to use recursion to find prime numbers of any integer entered by the user. Does anyone have any ideas on what I should do. typing out the code itself won't be too much of a problem, but I can't find a formula that will do the math.
Prime numbers of any integer? Do you mean the primes that divide into the number itself, or the number of primes lower than that number? Or do you mean x number of primes, where the user inputs x?
Try a loop with switch
This is the only information given by the professor:

Instructions: Write a program that will be able to get the prime factors of the number input by the user. Make sure your program implements a recursive algorithm.

Example: Prime factors of 25 = 5 * 5. prime factors of 60 = 2 * 2 * 3 * 5
Use a loop starting at one and divide by that number as much as possible then move on to next
 >Use a loop starting at one and divide by that number as much as possible then move on to next

1 is not a prime number

 > Make sure your program implements a recursive algorithm.

I might be wrong, but I'm sure this does not mean that the entire process of getting the prime has to be recursive, it can also recursively call a function lol.

I'm not sure if I'm right, but if you do implement an entirely recursive algorithm to solve this, you will be going deep. Like level 7 inception deep in the recursion because that means testing each integer for primeness, then storing that value in an array or however you wish to store all the values.

gl and post here if you make any progress
Last edited on
For any given number, you can find the first prime number by which it is evenly divisible by: beginning with the smallest number it may be divisible by (other than 1) and incrementing it until it is a number that evenly goes into the number in question.

You then have one factor (the divisor) and another value which needs to be factored (the quotient). If the quotient is 1, you're done.
Topic archived. No new replies allowed.