text: Average of a stream of numbers | C # program to find average of a stream of numbers ; Returns the new average after including x ; Prints average of a stream of numbers ; Driver Code
code: using System ; class GFG { static float getAvg ( float prev_avg , float x , int n ) { return ( prev_avg * n + x ) / ( n + 1 ) ; } static void streamAvg ( float [ ] arr , int n ) { float avg = 0 ; for ( int i = 0 ; i < n ; i ++ ) { avg = getAvg ( avg , arr [ i ] , i ) ; Console . WriteLine ( " Average ▁ of ▁ { 0 } ▁ " + " numbers ▁ is ▁ { 1 } " , i + 1 , avg ) ; } return ; } public static void Main ( String [ ] args ) { float [ ] arr = { 10 , 20 , 30 , 40 , 50 , 60 } ; int n = arr . Length ; streamAvg ( arr , n ) ; } }