Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Moving averages

using System.IO;
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] data = new int[] {100, 103, 110, 104, 110, 112, 106};
        
        CalcResults(5, data);
    }
    
    static void CalcResults(int lastX, int[] data){
        
        if(lastX > data.Length){
            Console.WriteLine("nil");
            return;
        }    
        
        for(int i=0; i <= (data.Length - lastX); i++){
            
            var testArray = data.Skip(i).Take(lastX);
            
            Console.WriteLine($"{testArray.Max()} {testArray.Min()} {Convert.ToInt32(testArray.Average())}");
        }
    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.