XOR and OR of all N | Function to check if a number is palindrome or not ; Convert the num n to string ; Iterate over string to check whether it is palindromic or not ; Function to find XOR of all N - digits palindrome number ; To store the XOR and OR of all palindromic number ; Starting N - digit palindromic number ; Ending N - digit palindromic number ; Iterate over starting and / ending number ; To check if i is palindromic or not ; Print the XOR and OR of all palindromic number ; Driver Code
function ispalin ( num ) { let s = num . toString ( ) ; let st = 0 , ed = s . length - 1 ; while ( st <= ed ) { if ( s [ st ] != s [ ed ] ) return false ; st ++ ; ed -- ; } return true ; } function CalculateXORandOR ( n ) { let CalculateXOR = 0 ; let CalculateOR = 0 ; let start = Math . pow ( 10 , n - 1 ) ; let end = Math . pow ( 10 , n ) - 1 ; for ( let i = start ; i <= end ; i ++ ) { if ( ispalin ( i ) ) { CalculateXOR = CalculateXOR ^ i ; CalculateOR = CalculateOR | i ; } } document . write ( " " + CalculateXOR ) ; document . write ( " " + CalculateOR ) ; } let n = 4 ; CalculateXORandOR ( n ) ;