Tidy Number ( Digits in non | C ++ program to check if a number is Tidy or not . ; Returns true if num is Tidy ; To store previous digit ( Assigning initial value which is more 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 isTidy ( int num ) { int prev = 10 ; while ( num ) { int rem = num % 10 ; num /= 10 ; if ( rem > prev ) return false ; prev = rem ; } return true ; } int main ( ) { int num = 1556 ; isTidy ( num ) ? cout << " Yes " : cout << " No " ; return 0 ; }