Open In App
Related Articles

Check if number is palindrome or not in Octal

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Given a number which may be in octal or in decimal. If the number is not octal then convert it into octal then check if it is palindrome or not. If it is palindrome then print 1 otherwise print 0. If the number is already in octal then check if the number is palindrome or not.
Examples : 
 

Input :n = 111
Output : Yes
Explanation:
all digits of 111 are in 0-7 so it 
is a octal number. Read 111 the result
is same backward and forward so it 
is a palindrome number. 

Input : 68
Output : No
Explanation:
68 is not a octal number because it's 
all digits are not in 0-7. So first we 
need to convert it into octal 
(68)base10(Decimal) = (104)base8(octal) 
104 is not palindrome.
 
Input : 97
Output : Yes
Explanation:
97 is not a octal number because it's all
digits are not in 0-7 so first we need to 
convert it into decimal to octal 
(97)base10(Decimal) = (141)base8(octal)  
141 is palindrome so output = 1.


 


Octal Number : The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7.
How to Convert Decimal Number to Octal Number : 
 

https://media.geeksforgeeks.org/wp-content/uploads/Capture-21.png


 

C++


                    

Java


                    

Python3


                    

C#


                    

PHP


                    

Javascript


                    

Output : 
 

Yes

Time complexity: O(logn) where n is given input number

Auxiliary Space: O(1)


 



Last Updated : 05 Sep, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads