Toph easy problem(Running Average Again)

Question:

Running Average Again

Limits: 1s, 512 MB

Given N numbers, read each one, calculate the running average and print it.
For example, given the 3 numbers 4, 2, and 7, print:
4
3
4.3333333333
The first number is the average of 4, the second number is the average of 4 and 2, the third number is the average of 4, 2 and 7.

Input

The first line of the input will contain N (N ≤ 100000).
The following line will contain N integers, each between 1 and 1000.

Output

Print the running average (accurate to 10-4) for each number, one per line.

Samples

InputOutput
3
4 2 7



Solve in C:

#include<stdio.h>
int main(){

int sum=0,i,n,a;
float   val;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    scanf("%d",&a);
    sum=sum+a;
    val=(float)sum/i;
printf("%f ",val);
}
return 0;

}

4
3
4.3333333333

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.