Write a program that determines how many positive and negative integers have been entered and calculates the total and average of all the entered numbers. code example
Example 1: Given two integers a and b, which can be positive or negative, find the sum of all the integers between including them too and return it. If the two numbers are equal return a or b.
getSum(1,3)
1 + getSum(2,3)
1 + ( 2 + getSum(3,3))
1 + ( 2 + (3))
Example 2: Given two integers a and b, which can be positive or negative, find the sum of all the integers between including them too and return it. If the two numbers are equal return a or b.
function getSum( a,b ){
if (a == b) return a; //(1)
if (a < b) {
return a + getSum(a+1, b); //(2)
}else {
return a + getSum(a-1,b); //(3)
}
}
getSum(1,3)