Average of first n even natural numbers | function to find average of sum of first n even numbers ; sum of first n even numbers ; calculating Average ; Driver Code
< ? php function avg_of_even_num ( $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) $ sum += 2 * $ i ; return $ sum / $ n ; } $ n = 9 ; echo ( avg_of_even_num ( $ n ) ) ; ? >