Check if a number starts with another number or not | C # program for the above approach ; Function to check if B is a prefix 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 prefix of A , then print " Yes "
using System ; class GFG { static bool checkprefix ( 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 [ i ] != s2 [ i ] ) { return false ; } } return true ; } static public void Main ( ) { int A = 12345 , B = 12 ; bool result = checkprefix ( A , B ) ; if ( result ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }