Find the unit place digit of sum of N factorials | Function to find the unit 's place digit ; Let us write for cases when N is smaller than or equal to 4. ; We know following ( 1 ! + 2 ! + 3 ! + 4 ! ) % 10 = 3 else ( N >= 4 ) ; Driver code
< ? php function get_unit_digit ( $ N ) { if ( $ N == 0 $ N == 1 ) return 1 ; else if ( $ N == 2 ) return 3 ; else if ( $ N == 3 ) return 9 ; return 3 ; } $ N = 1 ; for ( $ N = 0 ; $ N <= 10 ; $ N ++ ) echo " For ▁ N ▁ = ▁ " . $ N . " ▁ : ▁ " . get_unit_digit ( $ N ) . " STRNEWLINE " ; ? >