You can use the classical iterative approach to solve this problem as follows:
main.m121 chars9 lines
In this loop, we start with sum = 0
, and then in each iteration, we add the index i
to this sum. Finally, the loop is terminated when the index reaches n
. You can increase or decrease the value of n
and then run the loop to check if it's working correctly.
gistlibby LogSnag