Guest User

Untitled

a guest
Aug 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. void printPrimeFactors(int num)
  2. {
  3. bool found=false;
  4. int divider = 2;
  5.  
  6. if(num != 1)
  7. {
  8. //This while loops checks if the number is prime.
  9. while((found == false) || (divider == (num -1)))
  10. {
  11. if(num % divider != 0)
  12. divider++;
  13. else
  14. {
  15. //Printing of the prime number and stopping of the while loop.
  16. cout << divider << " ";
  17. found = true;
  18. }
  19. }
  20.  
  21. //If it's not prime, then we call the function again with a smaller number.
  22. printPrimeFactors(num / divider);
  23. }
  24. }
Add Comment
Please, Sign In to add comment