- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- 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 two digits of sum of N factorials using C++.

Here we will see how to get the last two digits. The unit place digit and the tens place digit of the sum of N factorials. So if N = 4, it will be 1! + 2! + 3! + 4! = 33. so unit place is 3 and ten place is 3. The result will be 33.

If we see this clearly, then as the factorials of N > 5, the unit place is 0, so after 5, it will not contribute to change the unit place. And after N > 10, the ten places will remain 0. For N = 10 and more, it will be 00. We can make a chart for N = 1 to 10 of factorial numbers.

We can solve this problem using these steps −

- If the value of n is less than 10, then (1! + 2! + … + n!) mod 10
- otherwise when value of n is greater or equal to 10, then (1! + 2! + … + 10!) mod 10 = 13

## Example

#include<iostream> #include<cmath> using namespace std; int getTenAndUnitPlace(long long N) { if (N <= 10) { long long ans = 0, factorial = 1; for (int i = 1; i <= N; i++) { factorial = factorial * i; ans += factorial; } return ans % 100; } return 13; } int main() { for(long long i = 1; i<15; i++){ cout << "Ten and Unit place value of sum of factorials when N = "<<i<<" is: " <<getTenAndUnitPlace(i) << endl; } }

## Output

Ten and Unit place value of sum of factorials when N = 1 is: 1 Ten and Unit place value of sum of factorials when N = 2 is: 3 Ten and Unit place value of sum of factorials when N = 3 is: 9 Ten and Unit place value of sum of factorials when N = 4 is: 33 Ten and Unit place value of sum of factorials when N = 5 is: 53 Ten and Unit place value of sum of factorials when N = 6 is: 73 Ten and Unit place value of sum of factorials when N = 7 is: 13 Ten and Unit place value of sum of factorials when N = 8 is: 33 Ten and Unit place value of sum of factorials when N = 9 is: 13 Ten and Unit place value of sum of factorials when N = 10 is: 13 Ten and Unit place value of sum of factorials when N = 11 is: 13 Ten and Unit place value of sum of factorials when N = 12 is: 13 Ten and Unit place value of sum of factorials when N = 13 is: 13 Ten and Unit place value of sum of factorials when N = 14 is: 13

- Related Questions & Answers
- Find the unit place digit of sum of N factorials using C++.
- Program to find last two digits of 2^n in C++
- Find sum of factorials in an array in C++
- Find largest sum of digits in all divisors of n in C++
- Product of first N factorials in C++
- Program to find last two digits of Nth Fibonacci number in C++
- Check if a given number divides the sum of the factorials of its digits in C++
- Program to find multiple of n with only two digits in Python
- Find the Number With Even Sum of Digits using C++
- Java Program to Find Sum of Digits of a Number using Recursion
- Program to find sum of digits in base K using Python
- C# program to find the sum of digits of a number using Recursion
- Find M-th number whose repeated sum of digits of a number is N in C++
- Program to find minimum digits sum of deleted digits in Python
- Find the overlapping sum of two arrays using C++

Advertisements