Count of Numbers in Range where first digit is equal to last digit of the number | C # program to implement the above approach ; Base Case ; Calculating the last digit ; Calculating the first digit ; Driver code
using System ; class GFG { public static int solve ( int x ) { int ans = 0 , first = 0 , last , temp = x ; if ( x < 10 ) return x ; last = x % 10 ; while ( x != 0 ) { first = x % 10 ; x /= 10 ; } if ( first <= last ) ans = 9 + temp / 10 ; else ans = 8 + temp / 10 ; return ans ; } public static void Main ( String [ ] args ) { int L = 2 , R = 60 ; Console . WriteLine ( solve ( R ) - solve ( L - 1 ) ) ; L = 1 ; R = 1000 ; Console . WriteLine ( solve ( R ) - solve ( L - 1 ) ) ; } }