Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void printPrimeFactors(int num)
- {
- bool found=false;
- int divider = 2;
- if(num != 1)
- {
- //This while loops checks if the number is prime.
- while((found == false) || (divider == (num -1)))
- {
- if(num % divider != 0)
- divider++;
- else
- {
- //Printing of the prime number and stopping of the while loop.
- cout << divider << " ";
- found = true;
- }
- }
- //If it's not prime, then we call the function again with a smaller number.
- printPrimeFactors(num / divider);
- }
- }
Add Comment
Please, Sign In to add comment