Question:
Assign the average of the values in the variables a , b , and c to a variable avg.?
m.d.
2011-01-15 18:36:08 UTC
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.
Three answers:
Light Cloud
2011-01-15 18:40:48 UTC
For C/C++/Java/C#, and perhaps more:



double avg = (a + b + c) / 3.0;
Raaj Bharath
2011-01-15 18:40:38 UTC
make the variables a,b,c as integers type variables as - int a,b,c

let average variable be labelled avg, declare it as floating point like - float avg

in calculation, use avg=(a+b+c)/3.

thats all.

while printing the result print as float.

printf("%f",avg);



//enjoy

//goodluck
?
2011-01-15 18:38:17 UTC
...



add them, divide by 3. IF they're int's or double or w/e, just cast to float, if you need to .


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...