Algorithm for Summing Natural Numbers
Input:
Set \( n = 50 \) (the upper limit of the natural numbers to sum).
Initialize Variables:
- Set
total = 0
to store the sum of the natural numbers.
- Set
series = ""
to store the string representation of the series.
Loop from 1 to \( n \):
For each \( i \) from 1 to \( n \) (i.e., \( i = 1, 2, 3, \ldots, n \)):
- Add \( i \) to
total
(i.e., total += i
).
- Append the string representation of \( i \) followed by " + " to
series
(i.e., series += f"{i} + "
).
Output the Series:
Print the string series
which contains the natural numbers from 1 to \( n \) concatenated with " + " symbols.
Output the Total Sum:
Print the value of total
, which represents the sum of natural numbers from 1 to \( n \).