Function to calculate sum of digits of an integer
static int getSum ( int n ) { int ans = 0 ; string str = n . ToString ( ) ; Char [ ] arr = str . ToCharArray ( ) ; foreach ( Char ch in arr ) { ans += ( int ) Char . GetNumericValue ( ch ) ; } return ans ; }