text: Average of even numbers till a given even number | C # Program to find average of even numbers till a given even number . ; Function to calculate the average of even numbers ; count even numbers ; store the sum of even numbers ; driver function
code: using System ; class GFG { static int averageEven ( int n ) { if ( n % 2 != 0 ) { Console . Write ( " Invalid ▁ Input " ) ; return - 1 ; } int sum = 0 , count = 0 ; while ( n >= 2 ) { count ++ ; sum += n ; n = n - 2 ; } return sum / count ; } public static void Main ( ) { int n = 16 ; Console . Write ( averageEven ( n ) ) ; } }