# Find last five digits of a given five digit number raised to power five 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

In this problem, we are given a number N. Our task is to find the last five digits of a given five digit number raised to power five.

Let’s take an example to understand the problem,

Input: N = 25211

Output:

## Solution Approach

To solve the problem, we need to find only the last five digits of the resultant value. So, we will find the last digit of the number after every power increment by finding the 5 digit remainder of the number.  At last return the last 5 digits after power of 5.

## Example

Live Demo

#include <iostream>
using namespace std;

int lastFiveDigits(int n) {
int result = 1;
for (int i = 0; i < 5; i++) {
result *= n;
result %= 100000;
}
cout<<"The last five digits of "<<n<<" raised to the power 5 are "<<result;
}

int main() {
int n = 12345;
lastFiveDigits(n);
return 0;
}

## Output

The last five digits of 12345 raised to the power 5 are 65625