Check if the sum of digits of number is divisible by all of its digits | C ++ implementation of the approach ; Function that returns true if all the digits of n divide the sum of the digits of n ; Store a copy of the original number ; Find the sum of the digits of n ; Restore the original value ; Check if all the digits divide the calculated sum ; If current digit doesn 't  divide the sum ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDivisible ( long long int n ) { long long int temp = n ; int sum = 0 ; while ( n ) { int digit = n % 10 ; sum += digit ; n /= 10 ; } n = temp ; while ( n ) { int digit = n % 10 ; if ( sum % digit != 0 ) return false ; n /= 10 ; } return true ; } int main ( ) { long long int n = 123 ; if ( isDivisible ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }