Showing posts with label Sum of 1..N natural numbers. Show all posts
Showing posts with label Sum of 1..N natural numbers. Show all posts

Friday, March 27, 2015

Sum of 1..N natural numbers

Algorithm
Step 1 : Start
Step 2 : Read n
Step 3 : Initialize 0 to sum and 1 to i
Step 4 : Add i to sum
Step 5 : Increment i by 1
Step 6: Repeat steps 4–6 until i􀀃􀂔 n
Step 7 : Print sum
Step 8 : Stop

Program (sum1ton.sh)
# Sum of 1+2+3+ ... +N numbers
echo -n "Enter N value : "
read n
sum=0
i=1