Вопрос задан 15.06.2023 в 18:36. Предмет Информатика. Спрашивает Ускова Дарья.

Программа которая использует цикл while и переменные счетчики найдите произведение всех четных

чисел от 1 до 10 !Срочно
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Мыхалчыч Витя.

Відповідь:

#include <iostream>

using namespace std;

int main(){

setlocale(LC_ALL, "Rus");

int counter = 1,product = 1;

while(counter < 10){

 if(counter % 2 == 0){

  product *= counter;

 }

 counter++;

}

cout << "Произведение всех четных чисел от 1 до 10 = " << product << endl;

return 0;

}

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Calculating the Product of Even Numbers from 1 to 10 Using a While Loop

To calculate the product of all even numbers from 1 to 10 using a while loop, we can use the following Python code:

```python # Initialize the variables num = 1 product = 1

# Use a while loop to iterate through the numbers from 1 to 10 while num <= 10: if num % 2 == 0: # Check if the number is even product *= num # Multiply the even number with the product num += 1 # Increment the number

# Print the result print("The product of all even numbers from 1 to 10 is:", product) ```

Output: The product of all even numbers from 1 to 10 is: 3840

This code initializes a variable `num` to 1 and a variable `product` to 1. It then uses a while loop to iterate through the numbers from 1 to 10. Within the loop, it checks if the number is even, and if so, multiplies it with the product. Finally, it prints the result.

[[2 #]]

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос