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.

Respuesta :

Answer:

Explanation:

Program PascalABC  and Result:

Ver imagen dedulja66let
belali

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;

}

Ver imagen belali