Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int* primeFactors(int n)
- {
- int* factorsArray = new int[10];
- // Get the prime factors of the number taken in as a parameter
- // 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.
- int counter = 0; //<-------------------------------
- for (int i = 2; i <= n; i++)
- {
- while (n % i == 0)
- {
- n /= i;
- cout << i << " ";
- factorsArray[counter] = i; //<-------------------------------
- counter++; //<-------------------------------
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement