Sum of integers upto N with given unit digit | Function to return the required sum ; If the unit digit is d ; Driver code
< ? php function getSum ( $ n , $ d ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { if ( $ i % 10 == $ d ) $ sum += $ i ; } return $ sum ; } $ n = 30 ; $ d = 3 ; echo getSum ( $ n , $ d ) ; ? >