
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Last Five Digits of a Five-Digit Number Raised to Power Five in C++
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.
Program to illustrate the working of our solution,
Example
#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
Advertisements