N
N
neitoo2021-10-20 19:54:10
C++ / C#
neitoo, 2021-10-20 19:54:10

Given integers A and B (A < B). Output all integers from A to B inclusive; while the number A should be displayed 1 time, the number A + 1 2 times?

int a12, b12, n12;
Console.Write("Введите число A -> "); a12 = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите число B -> "); b12 = Convert.ToInt32(Console.ReadLine());
if (a12 < b12)
  {
     for (; a12 <= b12; a12++)
         {
            Console.WriteLine(a12);
         }
   }
else
   {
        Console.WriteLine("Ошибка: A > B.");
    }

Now it simply displays, for example ,
2
3
4
And you need
2
3
3
4
4
4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-10-20
@neitoo

2. The code is as terrible as possible because of the names of the variables, line breaks, and entering variables in advance.
3. Validation is not needed, because by the condition of the problem it is guaranteed that A < B
4. You do not have enough loop to repeat the number N times

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question