Explanation:
Let solve the program using Java programming language
Method: method means group of statements to perform some operation.
let call the method sum.
Parameters: list of variables that are use in the method for declaration.
<u>The code</u>
public int sum (int number)
int answer;
if (number == 1)
answer = number;
else
{
int half = number/2;
int span = number - half;
answer = sum(half) + sum(span) + (half * span);
}
answer result;
}
Firstly we defined the method called sum(), the method takes only one parameter which is number and return the answer(sum of the integers 1 and N).
if the number is equal to 1, so it will return the number and if the number is not equal to 1 it will divide the number by 2 and get the span(span used to shift upper range).And result will add sum of half, sum of span and product of half span.