Program to find sum of first n natural numbers | Return the average of sum of first n even numbers ; If n is odd , ( n + 1 ) must be even ; Driver code
function findSum ( n ) { if ( n % 2 == 0 ) return ( n / 2 ) * ( n + 1 ) else return ( ( n + 1 ) / 2 ) * n } var n = 5 ; document . write ( findSum ( n ) ) ;