Has reached such code:

int i, s = 0, a[10], el = -1; a[0] = 3; a[1] = -1; a[2] = 2; a[3] = 0; n = 4; for(i=0; i<n;i++){ if(a[i]==0){ el = i; } break; } for (i = el; i<n; i++){ s+=fabs(a[i]); } Label3->Show(); if (el == -1){ Label3->Caption ="В массиве 0 нет"; } else if (el == (n-1)){ Label3 -> Caption = "0 является последним элементом"; } else { Label3->Caption = "Сумма равна "+IntToStr(s); } 

However, when running with these numbers instead of the conceived, "0 is the last element" displays "There is no 0 in the array". Where is the error, but I do not find

  • And what does n equal? You have not specified .. - Voidificator
  • Voidificator, I'm sorry, did not copy. 4 - Sergei Mikhailovskii
  • break; -> if () { ... } - Igor

2 answers 2

 for(i=0; i<n; i++) { if(a[i] == 0) { el = i; break; // должен быть тут } // а не тут } 
  • 2
    stopwatch finish? - Igor
  • 2
    15:52:50 both have, and SO in the database stores up to a second, so the draw: D - Qwertiy
  • Breaking the equality of votes. With comments, the answer is better than without ;-) - Kromster
 for (i = 0; i < n; i++) { if (a[i] == 0) { el = i; break; } }