Q:

Revise the program you wrote for the exercises that printed a range of numbers so that it handles input in which the first number is smaller than the second

0

Revise the program you wrote for the exercises in that printed a range of numbers so that it handles input in which the first number is smaller than the second.

#include <iostream>
int main()
{
int sum = 0, val = 1;
// keep executing the while as long as val is less than or equal to 10
while (val <= 10) {
sum += val; // assigns sum + val to sum
++val; // add 1 to val
}
std::cout << "Sum of 1 to 10 inclusive is "<< sum << std::endl;
return 0;
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>

int main() {
  int bg = 0, ed = 0;
  std::cout << "Enter the number of begin and end: ";
  std::cin >> bg >> ed;
  while (bg <= ed)
    std::cout << bg++ << " ";
  std::cout << std::endl;
  return 0;
}

 

Output:

Enter the number of begin and end: 1 25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now