Java program -07: To find Sum of Natural Numbers

in #natural7 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

Sort:  

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

Coin Marketplace

STEEM 0.25
TRX 0.20
JST 0.038
BTC 93413.26
ETH 3418.78
USDT 1.00
SBD 3.80