#include <iostream>
using namespace std;
int main() {
while (true) {
cout << "=====stop the cycle please enter 0 for first number====\n";
int a, b, Sum = 0;
cout << "Enter the first number: "; cin >> a;
cout << "Enter the second number: "; cin >> b;
if (a == 0 or b == 0) {
break;
}
if (a < b) {
for (int i = a + 1; i < b; i++) {
Sum += i;
}
cout << "The sum of numbers between [" << a << ", " << b << "] is " << Sum << endl;
}
else if (a > b) {
for (int i = b + 1; i < a; i++) {
Sum += i;
}
cout << "The sum of numbers between [" << b << ", " << a << "] is " << Sum << endl;
}
else {
cout << "The numbers are equal" << endl;
}
}
return 0;
}
Comments
Leave a comment