19.6k views
2 votes
Given two integers low and high representing a range, return the sum of the integers in that range. For example, if low is 12 and high is 18, the returned values should be the sum of 12, 13, 14, 15, 16, 17, and 18, which is 105. If low is greater than high, return 0.

2 Answers

2 votes

Answer:

Step-by-step explanation:

Program PascalABC and Result:

Given two integers low and high representing a range, return the sum of the integers-example-1
User Sashimi
by
4.0k points
3 votes

C++:

#include <iostream>

int sum_range(int l, int u, int sum) {

if(l>u) return 0;

else {

for(l;l<=u;l++) {

sum+=l;

}

return sum;

}

}

int main(int argc, char* argv[]) {

int l,u,sum; std::cin>>l>>u;

std::cout << "The result: " << sum_range(l,u,sum) << std::endl;

return 0;

}

Given two integers low and high representing a range, return the sum of the integers-example-1
User Soldiershin
by
4.5k points