Вопрос задан 27.02.2019 в 07:37. Предмет Информатика. Спрашивает Пищевая Катерина.

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

нельзя использовать инструкцию if.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Вороны Белые.
#include <stdio.h>
#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();
}
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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!

0 0

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

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

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