1 条题解

  • 0
    @ 2025-4-12 22:03:04

    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);
    }
    
    • 1

    信息

    ID
    2686
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者