Average of a stream of numbers - GeeksforGeeks
Given a stream of numbers, print average (or mean) of the stream at every point. For example, let us consider the stream as 10, 20, 30, 40, 50, 60, …
Read full article from Average of a stream of numbers - GeeksforGeeks
Given a stream of numbers, print average (or mean) of the stream at every point. For example, let us consider the stream as 10, 20, 30, 40, 50, 60, …
float
getAvg (
int
x)
{
static
int
sum, n;
sum += x;
return
(((
float
)sum)/++n);
}
// Prints average of a stream of numbers
void
streamAvg(
float
arr[],
int
n)
{
float
avg = 0;
for
(
int
i = 0; i < n; i++)
{
avg = getAvg(arr[i]);
printf
(
"Average of %d numbers is %f \n"
, i+1, avg);
}
return
;
}