VibraXX
Live Quiz Arena
🎁 1 Free Round Daily
⚡ Enter Arena
HomeCategoriesLogic & PuzzlesQuestion
Question
Logic & Puzzles

A program sums elements in an array; if the loop invariant 'sum of elements up to index i' is maintained, which consequence follows?

A)The program enters an infinite loop
B)The program computes the correct sum
C)The program throws an index error
D)The program produces a negative result

💡 Explanation

If the loop invariant is maintained, the partial sum is correctly updated in each iteration; because each element contributes correctly to the sum, the final result is correct. Therefore, the program computes the correct sum, rather than failing with errors which might happen if the invariant is not maintained.

🏆 Up to £1,000 monthly prize pool

Ready for the live challenge? Join the next global round now.
*Terms apply. Skill-based competition.

⚡ Enter Arena

Related Questions

Browse Logic & Puzzles