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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!