Find Sum of Series 1 ^ 2 | Function to find sum of series ; If n is even ; If n is odd ; return the result ; Get n ; Find the sum ; Get n ; Find the sum
< ? php function sum_of_series ( $ n ) { $ result = 0 ; if ( $ n % 2 == 0 ) { $ result = - ( $ n * ( $ n + 1 ) ) / 2 ; } else { $ result = ( $ n * ( $ n + 1 ) ) / 2 ; } return $ result ; } $ n = 3 ; echo sum_of_series ( $ n ) ; echo ( " STRNEWLINE " ) ; $ n = 10 ; echo sum_of_series ( $ n ) ; echo ( " STRNEWLINE " ) ; ? >