Program to check if a number is divisible by sum of its digits | C ++ implementation of above approach ; Converting integer to String ; Initialising sum to 0 ; Traversing through the String ; Converting character to int ; Comparing number and sum ; Driver Code ; Passing this number to get result function
#include <bits/stdc++.h> NEW_LINE using namespace std ; string getResult ( long long int n ) { string st = std :: to_string ( n ) ; int sum = 0 ; for ( char i : st ) { sum = sum + ( int ) i ; } if ( n % sum == 0 ) return " Yes " ; else return " No " ; } int main ( ) { int n = 123 ; cout << getResult ( n ) ; return 0 ; }