Here are two methods, iterative and recursive, which calculates the sum of all positive integers between 1 and a given integer n (input into the method). We know that as n gets larger, the solution takes longer to solve. Is there you think a much more efficient way of writing these codes?
NOTE: I'VE CROSS POST HERE
Is this the most efficient solution for taking the sum?
I'll let everyone know whether my answer is resolved from the other forum so I don't waste anybody's time. Thanks!
Iterative Method:
Recursive Method: