Find last two digits of sum of N factorials | C ++ program to find the unit place digit of the first N natural numbers factorials ; Function to find the unit ' s ▁ and ▁ ten ' s place digit ; Let us write for cases when N is smaller than or equal to 10. ; We know following ( 1 ! + 2 ! + 3 ! + 4 ! ... + 10 ! ) % 100 = 13 else ( N >= 10 ) ; Driver code
#include <iostream> NEW_LINE using namespace std ; #define ll  long int NEW_LINE int get_last_two_digit ( long long int N ) { if ( N <= 10 ) { ll ans = 0 , fac = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { fac = fac * i ; ans += fac ; } return ans % 100 ; } return 13 ; } int main ( ) { long long int N = 1 ; for ( N = 1 ; N <= 10 ; N ++ ) cout << " For ▁ N ▁ = ▁ " << N << " ▁ : ▁ " << get_last_two_digit ( N ) << endl ; return 0 ; }