The ratio of product to the sum#931

The ratio of product to the sum (Editorial)

Let's find the product and sum of the digits of the number . We will output the ratio of the product of the digits of the number to their sum.

Algorithm Implementation

Read the input number .

scanf("%d", &n);

We find the product of the digits of the number in the variable res. We find the sum of the digits of the number in the variable s. We initialize the variables.

res = 1; s = 0;

We iterate through the digits of the number. We divide the number by 10 until we get 0.

while (n > 0)
{
    s += n % 10;
    res = res * (n % 10);
    n /= 10;
}

We divide the product of the digits res by their sum s.

res /= s;

We output the answer.

printf("%.3lf\n", res);