Sum of first n odd numbers in O ( 1 ) Complexity | Efficient program to find sum of first n odd numbers ; Returns the sum of first n odd numbers ; Driver function
#include <iostream> NEW_LINE using namespace std ; int oddSum ( int n ) { return ( n * n ) ; } int main ( ) { int n = 20 ; cout << " ▁ Sum ▁ of ▁ first ▁ " << n << " ▁ Odd ▁ Numbers ▁ is : ▁ " << oddSum ( n ) ; return 0 ; }