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