# Number of Digits in a^b in C++

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

The power of a number can be computed using the iterative multiplication or function that the language provides. It's a straightforward thing.

Here, we have to find the a raised to power b. And the number of digits in the result. Let's see some examples.

Input

a = 5
b = 2

Output

2


Input

a = 7
b = 6

Output

6


## Algorithm

• Initialise the number a and b.
• Find the value of ab.
• The ceil of log10(n) will give you number of digits in the number n.
• Find it and return it.

## Implementation

Following is the implementation of the above algorithm in C++

#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