Here is the task: In the real array X = (x1, x2, ..., xn) each pair of x [i] and x [j] (i, j = 1, ..., n; i <> j) negative elements convert to positive elements using the formula x [i], x [j]: = sqrt (x [i] * x [j]). Pairs of elements (i, j) should be selected in the order of their sequence in the array X. Here is my intended solution:
void Mass::change(){ //int pos1 = 0; //int pos2 = 0; bool flag = false; for (int i = 0; i < dim; i++) { if (v[i] < 0) { int pos1 = 0; int pos2 = 0; for (int i = 0; i < dim; i++) { if (v[i] < 0) { flag = true; pos1 = i; } break; } for (int i = pos1 + 1; i < dim; i++) { if (v[i] < 0) { if (flag == true) { pos2 = i; v[pos1] = v[pos2] = sqrt(v[pos1] * v[pos2]); } else { flag = true; pos1 = i; } break; } } cout << "\n"; for (int i = 0; i < dim; i++) cout << v[i] << " "; // вывожу измененный массив cout << "\n" << pos1 << pos2; // проверяю запись позиций } } 
i. And what's the point of doing an unconditionalbreak;at the end of the cycle? - HolyBlackCati=0before the code? In addition, there remains a problem with the same variable for different nested loops ... - HolyBlackCat