Find last digit in factorial | C ++ program to find last digit in factorial n . ; Explicitly handle all numbers less than or equal to 4 ; For all numbers greater than 4 the last digit is 0 ; Driver code
#include <iostream> NEW_LINE using namespace std ; int lastDigitFactorial ( unsigned int n ) { if ( n == 0 ) return 1 ; else if ( n <= 2 ) return n ; else if ( n == 3 ) return 6 ; else if ( n == 4 ) return 4 ; else return 0 ; } int main ( ) { cout << lastDigitFactorial ( 6 ) ; return 0 ; }