Sum of n even natural numbers using while loop

 

Sum of n even natural numbers using while loop

n=int(input("Enter Number\t"))

sum=0

i=1 

print("The sum of n even numbers is:\t")

while i<=n :

    if i%2==0:

        sum=sum+i 

    i=i+1  

print(sum)

   Output:

Enter Number 10
The sum of n even numbers is:
30

टिप्पणी पोस्ट करा

0 टिप्पण्या