Is there any library function in c++ to do the operation?
There is no such function in the standard library. However, it is easy to implement and therefore an implementation may exist in another library.
Or i need to do it manually?
You can do it manually.
If I need to do it manually how can i do that?
Using the magic of maths. The following equivalence makes the implementation easy, using the natural logarithm function that is provided by the C++ standard library.
logb(x) = loge(x) / loge(b)
Where x
is any number greater than 0, logb is logarithm in base b
, and loge is the natural logarithm.
I have tried to do like that but it says "log x was not declared".
That is a likely result of trying to guess a name of a function. I would recommend to instead check the reference or a book for what functions are available.