S
S
Slavon72020-11-11 16:18:50
C++ / C#
Slavon7, 2020-11-11 16:18:50

Why doesn't it work and how is it better? Through for or if?

Given three numbers k, m, n. And you need to change so thatk<m<n

int main()
{
    int k = 5 ,m = 10 , n = 1; // k<m<n
    for (k < m; k++; k > m;) {

    }
    std::cout << k;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2020-11-12
@Slavon7

int k = 30, m = 560, n = 99;
int* a[] = { &k, &m, &n };

for (int i = 0; i < std::size(a) - 1; ++i)
{
  for (int j = 0; j < std::size(a) - i - 1; ++j)
  {
    if (*a[j] < *a[j + 1])
    {
      std::swap(*a[i], *a[i + 1]);
    }
  }
}
std::cout << k << " < " << m << " < " << n;

V
vreitech, 2020-11-11
@fzfx

You only need to take m and

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question