Question
C++ Write a function multibase which returns all the bases in which an integer is a palindrome. Consider the number 21, which in base 10
C++
Write a function multibase which returns all the bases in which an integer is a palindrome.
Consider the number 21, which in base 10 is not a palindrome. However, if we write 21 in base 2, the result is 10101, which is a palindrome.
In base 4, 21 is written as 111.
In base 6, 21 is written as 33.
In base 20, 21 is written as 11.
Hence, the function multibase(21) returns the string "2 4 6 20" since these are the bases in which the number 21 is a palindrome.
Here is the function signature
string multibase(int x)
The function multibase returns all the bases in which x is palindromic, from 2 to x-1 inclusive. Each palindromic base should be separated from the previous one by a space.
Restrictions
In your submitted work (any of the functions you write) you should not print out anything to cout or cerr, and you should not use terminal input cin.
You may only include the libraries iostream and string. No other includes are permitted.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started