Answers for "output sum of a range"

C++
0

output sum of a range

// get sum from x to y
// initialization of variables
int x = 1, y = 100, sum = 0;
// loop from x to y and add up the current index i
for(int i = x; i = y; i++) sum += i;
std::cout << sum;
Posted by: Guest on April-12-2022

Browse Popular Code Answers by Language