(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-2960223314593660", enable_page_level_ads: true }); Python program to print sum of all even numbers between 1 to n. - TecGlance

Header Ads

Python program to print sum of all even numbers between 1 to n.

Algorithm:::



Step 1: Start
Step 2: Read the limit of numbers, n
Step 3: Assign i=1
Step 4: Assign sum=0
Step 5: Repeat steps 6,7&8 until i=n reaches
Step 6: If i%2==0 goto step 7
Step 7: Compute sum=sum+i
Step 8: Compute i=i+1
Step 9: Print sum of even numbers, sum
Step 10: Stop

Flowchart:::


Program code:::
n=int(input('Enter the limit '))
i=1
sum=0
while i<n:
    if i%2==0:
        sum=sum+i
    i=i+1
print 'Sum of even numbers',sum


No comments

Powered by Blogger.