Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. int* primeFactors(int n)
  2. {
  3.  
  4. int* factorsArray = new int[10];
  5.  
  6. // Get the prime factors of the number taken in as a parameter
  7. // First see if n divided by i gives a whole number, if it does, divide by i again, if it does not, divide by i+1 and repeat the process.
  8.  
  9. int counter = 0; //<-------------------------------
  10. for (int i = 2; i <= n; i++)
  11. {
  12. while (n % i == 0)
  13. {
  14. n /= i;
  15. cout << i << " ";
  16. factorsArray[counter] = i; //<-------------------------------
  17. counter++; //<-------------------------------
  18. }
  19. }
  20.  
  21.  
  22.  
  23.  
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement