Sum of first n odd numbers in O ( 1 ) Complexity | Returns the sum of first n odd numbers ; Driver Code
< ? php function oddSum ( $ n ) { $ sum = 0 ; $ curr = 1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ sum += $ curr ; $ curr += 2 ; } return $ sum ; } $ n = 20 ; echo " ▁ Sum ▁ of ▁ first ▁ " , $ n , " ▁ Odd ▁ Numbers ▁ is : ▁ " , oddSum ( $ n ) ; ? >