Дано натуральное число n. Вычислить произведение
первых n сомножителей: 1/1 * 3/2 * 5/3........
Нужно зделать в С++

15 Сен 2019 в 23:42
309 +1
0
Ответы
1
include

double calculateProduct(int n) {
double product = 1.0;
double numerator = 1.0;
double denominator = 1.0;

for (int i = 0; i < n; i++) {
product *= numerator / denominator;
numerator += 2;
denominator++;
}
return product;

}

int main() {
int n;
std::cout << "Enter a natural number n: ";
std::cin >> n;

if (n <= 0) {
std::cout << "Please enter a natural number greater than 0." << std::endl;
} else {
double result = calculateProduct(n);
std::cout << "The product of the first " << n << " terms is: " << result << std::endl;
}
return 0;

}

19 Апр 2024 в 23:34
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир