#include <iostream> int main() { int a, b; std::cout << "Enter two natural numbers a and b: "; std::cin >> a >> b; int sum = 0; int product = 1; if (a < b) { for (int i = a + 1; i < b; i++) { sum += i; product *= i; } } else { for (int i = b + 1; i < a; i++) { sum += i; product *= i; } } std::cout << "Sum of numbers between a and b: " << sum << std::endl; std::cout << "Product of numbers between a and b: " << product << std::endl; return 0; }
Пример:
Enter two natural numbers a and b: 3 6 Sum of numbers between a and b: 12 Product of numbers between a and b: 60
int main() {
int a, b;
std::cout << "Enter two natural numbers a and b: ";
std::cin >> a >> b;
int sum = 0;
int product = 1;
if (a < b) {
for (int i = a + 1; i < b; i++) {
sum += i;
product *= i;
}
} else {
for (int i = b + 1; i < a; i++) {
sum += i;
product *= i;
}
}
std::cout << "Sum of numbers between a and b: " << sum << std::endl;
std::cout << "Product of numbers between a and b: " << product << std::endl;
return 0;
}
Пример:
Enter two natural numbers a and b: 3 6Sum of numbers between a and b: 12
Product of numbers between a and b: 60