84.5k views
0 votes
Assign the average of the values in the variables a, b, and c to a variable avg. Assume that the variables a, b, and c have already been assigned a value, but do not assume that the values are all floating-point. The average should be a floating-point value.

User Marnina
by
4.9k points

1 Answer

4 votes

Answer:

avg = (a+b+c)/3.0;

Step-by-step explanation:

The above mentioned statement will assign the average of three variable a, b,c and c to a float type variable avg.

In the above code making the divisor as 3.0 will make sure that the final result of expression evaluation comes out to be a floating point number.

If instead of 3.0 one would have used the number 3 then result of evaluation could have been an integer number of floating point number depending on the type of value of the expression a +b +c.

User JDx
by
5.4k points