(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-2960223314593660", enable_page_level_ads: true }); Program to find the sum of n natural numbers - TecGlance

Header Ads

Program to find the sum of n natural numbers



Program to find the sum of n natural numbers

Algorithm :::
  
    Step 1 : Start
    Step 2 : Assign sum=0 and i=0
    Step 3 : Read limit of number , n
    Step 4 : Repeat steps 5 to 6 until i=n reached
    Step 5 : Compute sum=sum+i
    Step 6 : Compute i=i+1
    Step 7 : Print sum
    Step 8 : Stop

  Flowchart :::
































Program:::

  sum=0
  i=0
  n=input("Enter the number : ")
  while i<=n:
      sum=sum+i
      i=i+1
  print"Sum is ",sum


Output:::

Enter the number :  5
Sum is  15
 
Enter the number :  6
Sum is  21

   

 

No comments

Powered by Blogger.