Creating a sum function
Below is an example of how to calculate the total of a sequence of numbers. In this case we will be calculating the sum of 10 + 9 + … + 2 + 1
Example:
sum(10);
Result:
55
Iterative version of a function that calculates the summation
To understand how to calculate the sum using recursion, let’s write a simple algorithm that will do it for us using iteration.
int total = 0;
//We want the sum from 1 + 2 + … + 9 + 10
int n = 10;
//The following for loop will calculate the summation from 1 – n
for ( int i = 1; i < = n; i++ ) {
total = total + i;
}




I was user of 
