Вопрос задан 08.08.2018 в 06:01. Предмет Информатика. Спрашивает Латфуллина Мадина.

с помощью цикла do while четные и нечетные числа в c++

0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Иринархов Тимофей.
Int  i = 0;
while(++i != 10) {
      if (!(i % 2)) cout << i << " ";
}
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Using a Do-While Loop to Identify Even and Odd Numbers in C++

To use a do-while loop to identify even and odd numbers in C++, you can follow the steps below.

1. Initialize Variables: - Start by initializing variables for the number to be checked and for storing the result.

```c++ int num; // Number to be checked int evenCount = 0; // Variable to count even numbers int oddCount = 0; // Variable to count odd numbers ```

2. Input the Number: - Prompt the user to input the number to be checked.

```c++ cout << "Enter a number: "; cin >> num; ```

3. Do-While Loop: - Use a do-while loop to check if the number is even or odd and update the respective count variables.

```c++ do { if (num % 2 == 0) { evenCount++; // Increment even count if the number is even } else { oddCount++; // Increment odd count if the number is odd } cout << "Enter another number (or 0 to exit): "; cin >> num; } while (num != 0); ```

4. Output the Results: - Display the counts of even and odd numbers entered by the user.

```c++ cout << "Total even numbers entered: " << evenCount << endl; cout << "Total odd numbers entered: " << oddCount << endl; ```

This code prompts the user to enter numbers until they input 0, and it keeps track of the count of even and odd numbers entered.

0 0

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

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

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