K | C # program for the above approach ; Function to find the kth digit from last in an integer n ; If k is less than equal to 0 ; Convert integer into string ; If k is greater than length of the string temp ; Print the k digit from last ; Driver code ; Given Input ; Function call
using System ; using System . Collections . Generic ; class GFG { static void kthDigitFromLast ( int n , int k ) { if ( k <= 0 ) { Console . Write ( - 1 ) ; return ; } string temp = n . ToString ( ) ; if ( k > temp . Length ) { Console . WriteLine ( - 1 ) ; } else { Console . Write ( temp [ temp . Length - k ] - 48 ) ; } } public static void Main ( ) { int n = 2354 ; int k = 2 ; kthDigitFromLast ( n , k ) ; } }