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


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

while(++i != 10) {
if (!(i % 2)) cout << i << " ";
}



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.


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







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili