Check if a number is a Mystery Number | C # implementation of above approach ; Finds reverse of given num x . ; if found print the pair , return
using System ; class GFG { static int reverseNum ( int x ) { string s = x . ToString ( ) ; string str = " " ; for ( int i = s . Length - 1 ; i >= 0 ; i -- ) { str = str + s [ i ] ; } int rev = Int32 . Parse ( str ) ; return rev ; } static bool isMysteryNumber ( int n ) { for ( int i = 1 ; i <= n / 2 ; i ++ ) { int j = reverseNum ( i ) ; if ( i + j == n ) { Console . WriteLine ( i + " ▁ " + j ) ; return true ; } } Console . WriteLine ( " Not ▁ a ▁ Mystery ▁ Number " ) ; return false ; } public static void Main ( ) { int n = 121 ; isMysteryNumber ( n ) ; } }