Back to all tasks

Calculate Array Sum

You are provided with a C++ function calculateArraySum that is intended to compute the sum of all integer elements in a given array. The function takes two arguments: an integer array arr and its size n.

Currently, the function contains an error in its loop condition and is missing the accumulation logic.

Your task is to:

  1. Fix the bug in the loop condition to ensure all elements are processed correctly.
  2. Complete the logic inside the loop to correctly accumulate the sum.
  3. Ensure the function returns the correct total sum.
calculate_array_sum.cpp
Loading...

Use the "Verify Solution" button to get AI feedback on your c++ code.