Sum of first n odd numbers

# Sum of first n odd numbers

Nterms = int(input("Enter number of terms:"))

counter = 0
total = 0
num = 1

while(counter < Nterms):
total += num
num += 2
counter += 1

print("Sum of first n odd numbers is", total)

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu