I need to write a program that will calculate the arithmetic and geometric average of 10 variables. When I run tests on the program, it fails to calculate the geometric mean when there are numbers that include zero, for instance the series: 3 2 1 0 0 0 2 1 1 8; The output should be 1.9195
*(when all the variables are 0, the output should be that there is no answer, but when there are zeros in addition to other numbers- it should exclude them and calculate only the natural numbers)
#include <stdio.h>
#include <math.h>
void main()
{
int num, i;
float sum, mult;
printf("Enter 10 variables: ");
sum = 0;
mult = 1;
for (i=0; i<10; i++)
{
scanf("%d", &num);
sum += num;
mult *= num;
}
if (mult == 0 || mult < 0)
{
printf("No positive numbers, hence no geometric mean");
}
else
{
printf(" %.4f", pow(mult, (1.0 / i)));
}
printf(" %.4f", sum / i);
}