Sum of integers upto N with given unit digit ( Set 2 ) | C # implementation of the approach ; Function to return the required sum ; Decrement N ; Driver code
class GFG { static int getSum ( int n , int d ) { if ( n < d ) return 0 ; while ( n % 10 != d ) n -- ; int k = n / 10 ; return ( k + 1 ) * d + ( k * 10 + 10 * k * k ) / 2 ; } public static void Main ( ) { int n = 30 ; int d = 3 ; System . Console . WriteLine ( getSum ( n , d ) ) ; } }