游客 Signup | Login
中文 | En

2030 - P315 14

P315 14


你的main函数的内容为:

int main()<br />

{
    int x = 1;
    float avg;
int n;

cin>>n;

while (x < 20){
   avg = RunningAvg(x);
 cout<<"Average is: "<<avg<<endl;
 x= x +3;
}

   return 0;
}

<br />

Input

n

Output

每次调用后函数的返回结果。

Examples

Input

20

Output

Average is: 1
Average is: 2.5
Average is: 4
Average is: 5.5
Average is: 7
Average is: 8.5
Average is: 10

Solution C++

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

float RunningAvg(float);

int main()
{
	int x = 1;
	float avg;
	int n;

	cin>>n;

	while (x < 20)
	{
		avg = RunningAvg(x);
		cout<<"Average is: "<<avg<<endl;
		x= x +3;
	}
}

float RunningAvg(float a)
{
	static float total = 0.0;
	static int count = 0;
	total = total + a;
	count++;
	return total/float(count);
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题