Check if a number ends with another number or not | C # program for the above approach ; Function to check if B is a suffix of A or not ; Convert numbers into strings ; Find the lengths of strings s1 and s2 ; Base case ; Traverse the strings s1 & s2 ; If at any index characters are unequals then return false ; Return true ; Driver code ; Given numbers ; Function Call ; If B is a suffix of A , then print " Yes "
using System ; class GFG { public static bool checkSuffix ( int A , int B ) { string s1 = A . ToString ( ) ; string s2 = B . ToString ( ) ; int n1 = s1 . Length ; int n2 = s2 . Length ; if ( n1 < n2 ) { return false ; } for ( int i = 0 ; i < n2 ; i ++ ) { if ( s1 [ n1 - i - 1 ] != s2 [ n2 - i - 1 ] ) { return false ; } } return true ; } public static void Main ( string [ ] args ) { int A = 12345 , B = 45 ; bool result = checkSuffix ( A , B ) ; if ( result ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }