Exponents and Roots

Nucular

Baseband Member
Messages
39
I am pretty new to C++, and i was wondering if there was any way to do exponents and roots. Your time is much appreciated.
 
yes, include the cmath library.

Exponents --> exp(x) - where x is the power you want to raise to, or pow(x,y) --> x raised to the power y.

Roots --> sqrt(x) - square root of x
 
To get the square root of a number, all you need to do is raise it to the power of a half.

So, 9^0.5 = sqrt(9) = 3.

But <cmath> is a far more elegant way of doing it, IMHO.
 
I should have known that. Thank-you for enlightening me UK. btw, have you ever golfed at St. Andrew's?
 
UK31337 said:
To get the square root of a number, all you need to do is raise it to the power of a half.

So, 9^0.5 = sqrt(9) = 3.

But <cmath> is a far more elegant way of doing it, IMHO.

oh yes of course there are other methods to do the same calculations. I do agree though, that cmath does make things so much easier and less work. Programmers, after all, I find are lazy and want to get things done in the quickest way possible with the least amount of code :)

- ooh, this was my 666th post.....devilish!
 
if you want to find other roots you can just raise the number you want to find the root of to the right decimal. for example: cube, = 1/3 .33333 forever, fourth = 1/4 = .25 ect.
 
Back
Top Bottom