What opportunities are there for the next task ???

// массивы. Проинициализируйте трехмерный массив //double dArray[4][3][3] так, как показано на рисунке и напишите фрагмент //кода, который меняет местами значения элементов четных //и нечетных слоев: // было: |--------| // / |4 4 4 | // |--------| 4 | // / |3 3 3 | 4 | // |---------|3 | | // / | 2 2 2 |3 | / // |---------|2 |__| // | 1 1 1 |2 | / // | 1 1 1 |__| // | 1 1 1 | / // |_________| // стало: |--------| // / |3 3 3 | // |--------| 3 | // / |4 4 4 | 3 | // |---------|4 | | // / | 1 1 1 |4 | / // |---------|1 |__| // | 2 2 2 |1 | / // | 2 2 2 |__| // | 2 2 2 | / // |_________| for(int i=0; i<...; ...) { //Замечание: НЕ НУЖНО МОДИФИЦИРОВАТЬ ВЫРАЖЕНИЯ СПРАВА ОТ ЗНАКА РАВЕНСТВА!!! ... = dArray[i]; ... = dArray[i+1]; //переставляем местами элементы i-того и i+1-ого слоев } 
  • So напишите фрагмент кода or заполните недостающие фрагменты кода ? I doubt the second can be solved. - vp_arth
  • @vp_arth why not? nobody forbids to write 1 more line below. - pavel
  • It's just that there are no dots there) However, this line can be pressed into cycle increment) - vp_arth
  • and if with the addition of the missing code, how? - Vladimir

1 answer 1

If "with the addition of the missing code", then, for example,

 for (int i = 0; i + 1 < 4; i += 2) { auto &even_layer = dArray[i]; auto &odd_layer = dArray[i+1]; std::swap(even_layer, odd_layer); } 

or to abstract from the constant 4

 for (int i = 0; i + 1 < std::extent<decltype(dArray)>::value; i += 2) ... 

Of course, if you aim to enter the code only in ellipses, then you can spew something like “creaking from your heart”

 for (int i = 0; i + 1 < std::extent<decltype(dArray)>::value; i += 2) { auto dummy = dArray[i]; (std::swap(dArray[i], dArray[i + 1]), dummy) = dArray[i + 1]; } 

But I doubt it makes sense.

  • thank you !! I braked something! - Vladimir