Sum and Product of digits in a number that divide the number | C ++ implementation of the above approach ; Print the sum and product of digits that divides the number . ; Fetching each digit of the number ; Checking if digit is greater than 0 and can divides n . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countDigit ( int n ) { int temp = n , sum = 0 , product = 1 ; while ( temp != 0 ) { int d = temp % 10 ; temp /= 10 ; if ( d > 0 && n % d == 0 ) { sum += d ; product *= d ; } } cout << " Sum ▁ = ▁ " << sum ; cout << " Product = " } int main ( ) { int n = 1012 ; countDigit ( n ) ; return 0 ; }