Number of Digits in a^b in C++

C++Server Side ProgrammingProgramming

In this tutorial, we are going to write a program that finds the number of digits in the number ab

Let's see the steps to solve the problem.

• Initialise the number a and b.

• Find the value of ab

• Find the number of digits using log.

Example

Let's see the code.

Live Demo

#include <bits/stdc++.h>
using namespace std;
int getDigitsCount(int a, int b) {
return ceil(log10(pow(a, b)));
}
int main() {
int a = 8;
int b = 3;
cout << getDigitsCount(a, b) << endl;
return 0;
}

Output

If you run the above code, then you will get the following result.

3

Conclusion

If you have any queries in the tutorial, mention them in the comment section.

Published on 03-Jul-2021 04:59:21