Check if all prefixes of a number is divisible by remaining count of digits | C ++ program for the above approach ; Function to check if all prefixes of a number is divisible by remaining count of digits or not ; Traverse and check divisibility for each updated number ; Update the original number ; Driver Code ; Given Input ; Function Call
#include <iostream> NEW_LINE using namespace std ; bool prefixDivisble ( int n ) { int i = 1 ; while ( n > 0 ) { if ( n % i != 0 ) return false ; n = n / 10 ; i ++ ; } return true ; } int main ( ) { int n = 52248 ; if ( prefixDivisble ( n ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }