|
| |||||||||||||||||||||||||||||||||||||||||||
| Console (18) | |
|
Hey, I was wondering if anyone knew (Zaita, most likely...) how to write out the square root algorithm into C++ to make it spit out the answer to what the user puts in. This is probably very long and complicated code, considering a lot of guessing and fixing comes with pencil-and-paper method, but I'll give you credit in the program if you help me. Example of pencil-and-paper algorithm: √645: *****2 5 . 39 ****√6.45.00.00 ****- 4 * (45) 245 **** -225 *(503) 20 00 ***** -1509 **(5069) 491 00 Answer: About 25.4. | |
|
Last edited on
|
|
| Console (18) | |
| BUMMPPPP | |
|
|
|
| firedraco (4744) | |
| Well....It'd be quite annoying, but certainly doable...I would probably read the number into a string so that I can get each digit individually, then go around and check the "first" number, then check the modulus of it...if it works, subtract it and output the work...then change the original string to be modified...if it doesn't, take the first two, etc... | |
|
|
|
| jsmith (5804) | |
|
There are easier algorithms to implement than that. See http://en.wikipedia.org/wiki/Square_root The Babylonian method is pretty simple to implement. | |
|
|
|
| hetrox (2) | |
|
To calculate the square root of a number you can use the predefined libaray function of sqrt(). e.g if the user input is x, sqrt(x); will calculate the squareroot. The header file for this is <math.h> | |
|
|
|