write a C function which takes a natural number as argument and calculates the product of sum of its digits. A sum-product number is natural number that equals the product of sum of its digits and the product of digits.

1 answer

well, the hardest part is picking off the digits of the number. That is easily done by taking the remainder when dividing by 10.

So, if the number is n, this can be achieved by the following loop:

int n,d;
d=0;
while (n > 0) {
d = n%10;
#now you have the ones' digit #use it for the sum and product
n /= 10; # integer division
}

I'm sure you can fill in the rest.