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
Output:
sum of first 10 natural numbers is : 55
Example 2: Program to calculate the sum of natural numbers using for loop
Output :
sum of first 10 natural numbers is : 55
Example 3: Program to find sum of first n (entered by user) natural numbers
Output :
Enter the value of n:
20
Sum of first 20 natural numbers is : 210
This post has received a 55.45 % upvote from @steemfeed thanks to: @afjal.softcare.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit