Check if number is palindrome or not in base B | C ++ program to implement the above approach ; Function to check if N in base B is palindrome or not ; Stores the reverse of N ; Stores the value of N ; Extract all the digits of N ; Generate its reverse ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int checkPalindromeB ( int N , int B ) { int rev = 0 ; int N1 = N ; while ( N1 ) { rev = rev * B + N1 % B ; N1 = N1 / B ; } return N == rev ; } int main ( ) { int N = 5 , B = 2 ; if ( checkPalindromeB ( N , B ) ) { cout << " Yes " ; } else { cout << " No " ; } }