Find nth term of the series 5 2 13 41 | function to calculate nth term of the series ; if n is even number ; if n is odd number ; return nth term ; Driver code
< ? php function nthTermOfTheSeries ( $ n ) { if ( $ n % 2 == 0 ) $ nthTerm = pow ( $ n - 1 , 2 ) + $ n ; else $ nthTerm = pow ( $ n + 1 , 2 ) + $ n ; return $ nthTerm ; } $ n = 8 ; echo nthTermOfTheSeries ( $ n ) . " STRNEWLINE " ; $ n = 12 ; echo nthTermOfTheSeries ( $ n ) . " STRNEWLINE " ; $ n = 102 ; echo nthTermOfTheSeries ( $ n ) . " STRNEWLINE " ; $ n = 999 ; echo nthTermOfTheSeries ( $ n ) . " STRNEWLINE " ; $ n = 9999 ; echo nthTermOfTheSeries ( $ n ) . " STRNEWLINE " ; ? >