Repdigit Numbers | C ++ implementation to check if a number is Repdigit ; Function to check if a number is a Repdigit number ; To store previous digit ( Assigning initial value which is less than any digit ) ; Traverse all digits from right to left and check if any digit is smaller than previous . ; Driver code
#include <iostream> NEW_LINE using namespace std ; bool isRepdigit ( int num , int b ) { int prev = -1 ; while ( num ) { int digit = num % b ; num /= b ; if ( prev != -1 && digit != prev ) return false ; prev = digit ; } return true ; } int main ( ) { int num = 2000 , base = 7 ; isRepdigit ( num , base ) ? cout << " Yes " : cout << " No " ; return 0 ; }