Well, you can use the same logarithmic functions here too. Include cmath
.
In-code
.
.
cout << log(8) / log(3) << endl;
.
.
Output
.
.
.
...3...
.
.
.
Question
How can we calculate the value/degree of power exponent of a certain number?
I mean if it's like a^n = b, then how can we calculate n?
For example assume that a = 2 and b = 8, then how can we calculate that n = 3? Is there any special function?
Solution 3
Well, you can use the same logarithmic functions here too. Include cmath
.
In-code
.
.
cout << log(8) / log(3) << endl;
.
.
Output
.
.
.
...3...
.
.
.
OTHER TIPS
What you are looking for is the logarithm of b to the base a (at least we call it that in german).
C++ example:
#include <cmath> /* log */
int main ()
{
int a = 2;
int b = 8;
float n = log(b) / log(a); // 3
}