Program to find sum of first n natural numbers | Returns sum of first n natural numbers ; If n is odd , ( n + 1 ) must be even ; Driver code
< ? php function findSum ( $ n ) { if ( $ n % 2 == 0 ) return ( $ n / 2 ) * ( $ n + 1 ) ; else return ( ( $ n + 1 ) / 2 ) * $ n ; } $ n = 5 ; echo findSum ( $ n ) ; ? >