
Написать программу, на языке Си, выводящую все чётные числа на отрезке от A до B. В этой задаче
нельзя использовать инструкцию if.

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

#include <conio.h>
int main (int argc, char *argv[])
{
int A, B;
printf("A = ");scanf("%d", &A);
printf("B = ");scanf("%d", &B);
A = A + A % 2;
B = B - B % 2;
for (A = A; A<=B; A = A+2)
printf("%d ", A);
getch();
}



Program to Print Even Numbers in a Range without Using if Statement in C
Here's a program written in the C programming language that prints all the even numbers in a given range from A to B, without using the `if` statement:
```c
#include
int main() { int A, B; printf("Enter the range (A and B): "); scanf("%d %d", &A, &B);
int number = A % 2 == 0 ? A : A + 1; while (number <= B) { printf("%d ", number); number += 2; }
return 0; } ```
Explanation: 1. The program starts by prompting the user to enter the range A and B. 2. The variable `number` is initialized to A if A is even, or A + 1 if A is odd. 3. The program then enters a `while` loop that continues until `number` exceeds B. 4. Inside the loop, the current value of `number` is printed, and then `number` is incremented by 2 to move to the next even number. 5. The loop continues until `number` exceeds B, printing all the even numbers in the range.
Please note that this program assumes that A and B are integers and that A is less than or equal to B.
Let me know if you have any further questions!


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