Program to check if a number is divisible by any of its digits | C ++ implementation of above approach ; Function to check if given number is divisible by any of its digits ; check if any of digit divides n ; check if K divides N ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string isDivisible ( long long int n ) { long long int temp = n ; while ( n ) { int k = n % 10 ; if ( temp % k == 0 ) return " YES " ; n /= 10 ; } return " NO " ; } int main ( ) { long long int n = 9876543 ; cout << isDivisible ( n ) ; return 0 ; }