Check if number is palindrome or not in Octal | C # program to check if octal representation of a number is prime ; Function to Check no is in octal or not ; Function To check no is palindrome or not ; If number is already in octal , we traverse digits using repeated division with 10. Else we traverse digits using repeated division with 8 ; To store individual digits ; Traversing all digits ; checking if octal no is palindrome ; Driver Code
using System ; class GFG { static long MAX_DIGITS = 20 ; static long isOctal ( long n ) { while ( n > 0 ) { if ( ( n % 10 ) >= 8 ) return 0 ; else n = n / 10 ; } return 1 ; } static long isPalindrome ( long n ) { long divide = ( isOctal ( n ) == 0 ) ? 8 : 10 ; long [ ] octal = new long [ MAX_DIGITS ] ; long i = 0 ; while ( n != 0 ) { octal [ i ++ ] = n % divide ; n = n / divide ; } for ( long j = i - 1 , k = 0 ; k <= j ; j -- , k ++ ) if ( octal [ j ] != octal [ k ] ) return 0 ; return 1 ; } static int Main ( ) { long n = 97 ; if ( isPalindrome ( n ) > 0 ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; return 0 ; } }