Program to check if a number is divisible by any of its digits | C ++ implementation of above approach ; Converting integer to string ; Traversing the string ; find the actual digit ; If the number is divisible by digits then return yes ; If no digits are dividing the number then return no ; Driver Code ; passing this number to get result function
#include <bits/stdc++.h> NEW_LINE using namespace std ; string getResult ( int n ) { string st = to_string ( n ) ; for ( int i = 0 ; i < st . length ( ) ; i ++ ) { int d = st [ i ] - 48 ; if ( n % d == 0 ) { return " Yes " ; } } return " No " ; } int main ( ) { int n = 9876543 ; cout << getResult ( n ) ; }