Check whether sum of digits at odd places of a number is divisible by K | C ++ implementation of the approach ; function that checks the divisibility of the sum of the digits at odd places of the given number ; if position is odd ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool SumDivisible ( int n , int k ) { int sum = 0 , position = 1 ; while ( n > 0 ) { if ( position % 2 == 1 ) sum += n % 10 ; n = n / 10 ; position ++ ; } if ( sum % k == 0 ) return true ; return false ; } int main ( ) { int n = 592452 ; int k = 3 ; if ( SumDivisible ( n , k ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }