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
def findSum ( n ) : NEW_LINE INDENT if ( n % 2 == 0 ) : NEW_LINE INDENT return ( n / 2 ) * ( n + 1 ) NEW_LINE DEDENT else : NEW_LINE return ( ( n + 1 ) / 2 ) * n NEW_LINE DEDENT n = 5 NEW_LINE print findSum ( n ) NEW_LINE