Square Root ?!?

This is a discussion on Square Root ?!? within the C++ Programming forums, part of the General Programming Boards category; I want to make a program that can find the square root of a number. Yes, I do know about ...

Square Root ?!?

I want to make a program that can find the square root of a number. Yes, I do know about the sqrt() function. However, I don't want to find the square root of a number in decimal form. For instance, if I wanted to know the square root of 45, I want it to output "3 times the square root of 5."

OK, OK... I'm guessing you want to know how to go about doing this. First of all, I'd ry putting questions like these in maybe the tech board, or something else to deal with general algorithms, but since I don't have the power to do this...

There are all sorts of mathemaical rules about simplifying square roots into things like the example you cited. My advice would be to just build some data structures that allow the computer to go through and factor the number (which wouldn't be too hard - just reduce the number down to primes). Find out if x % 2 = 0, and so forth, constanrtly extracting until you get a list of primes. Extract duplicates from this list, place them outside the radical, and convert that data into an English sentence. Sounds like a fun porject actually.