Need a Perfect Square Factorer
Feb 14, 2013 at 2:37am UTC
I'm having trouble with a function of mine. It is supposed to factor out all the perfect squares within a number. For example, say the number was 24160, I need the program to factor out 16 as the perfect square and leave 1510 as the other part.
Here's what I have so far:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 //getSimplifiedRad function
void getSimplifiedRad( double squareRoot, double &endRad, double &outRad)
for ( int simplifier = 2; simplifier * simplifier <= squareRoot; simplifier++)
//Simplifier will always be a perfect square
if (getIsPrime(squareRoot/(simplifier*simplifier)) == true)
squareRoot /= (simplifier * simplifier);
if (getIsPrime(squareRoot) == true && getIsPerfSquare(simplifier) == true)
endRad = squareRoot;
outRad = simplifier;
} //End if
} //End if
} //End for loop
//End of getSimplifiedRad function
(Yes, this is for a quadratic equation program)
This has been giving me trouble for a while, and I have re-written it twice.
Last edited on
Feb 14, 2013 at 3:07am UTC
Topic archived. No new replies allowed.