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
using System ; public class GFG { static String getResult ( int n ) { String st = String . Join ( " " , n ) ; int sum = 0 ; foreach ( char i in st . ToCharArray ( ) ) { sum = sum + ( int ) i ; } if ( n % sum == 0 ) return " Yes " ; else return " No " ; } public static void Main ( String [ ] args ) { int n = 123 ; Console . WriteLine ( getResult ( n ) ) ; } }