Algorithm to find the sum of first n natural numbers:
1. Read n.
2. Initialize i=1.
3. Initialize sum s=0.
4. Repeat step 4 to step 6 until i=n
5. Calculate s=s+i.
6. Calculate i=i+1.
7. print sum
8. Stop.
1. Read n.
2. Initialize i=1.
3. Initialize sum s=0.
4. Repeat step 4 to step 6 until i=n
5. Calculate s=s+i.
6. Calculate i=i+1.
7. print sum
8. Stop.
No comments:
Post a Comment