Java program -07: To find Sum of Natural Numbers

in natural •  7 years ago 

278px-Three_apples(1).svg.png

Natural Numbers program :

The positive integers 1, 2, 3, 4 etc. are known as natural numbers. Here we will see three programs to calculate and display the sum of natural numbers.

 First Program calculates the sum using while loop
 Second Program calculates the sum using for loop
 Third Program takes the value of n(entered by user) and calculates the sum of n natural numbers

Example 1: Program to find the sum of natural numbers using while loop

nnwl.PNG

Output:

sum of first 10 natural numbers is : 55

Example 2: Program to calculate the sum of natural numbers using for loop

nnfl.PNG

Output :

sum of first 10 natural numbers is : 55

Example 3: Program to find sum of first n (entered by user) natural numbers

nnu.PNG

Output :

Enter the value of n:
20
Sum of first 20 natural numbers is : 210

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

This post has received a 55.45 % upvote from @steemfeed thanks to: @afjal.softcare.