Skip to content

Separate sum accumulator from average in Multidimensional Arrays exercise - #886

Open
icaromol wants to merge 1 commit into
ronreiter:masterfrom
icaromol:fix/split-sum-average-multidim-arrays
Open

Separate sum accumulator from average in Multidimensional Arrays exercise#886
icaromol wants to merge 1 commit into
ronreiter:masterfrom
icaromol:fix/split-sum-average-multidim-arrays

Conversation

@icaromol

@icaromol icaromol commented Aug 5, 2026

Copy link
Copy Markdown

Summary

  • The Multidimensional Arrays exercise (learn-c.org) reused a single average variable both as the running sum accumulator and as the final computed average, which is a confusing pattern for beginners.
  • Introduces a separate sum variable to accumulate grades; average is now only assigned once, after the sum is known.
  • Applied consistently to both the Tutorial Code and Solution sections.

No behavior change — output is still:

The average marks obtained in subject 0 is: 78.80
The average marks obtained in subject 1 is: 82.80

Test plan

  • Compiled the updated Solution with gcc -Wall and confirmed output matches exactly.
  • Diff limited to the two float/accumulator lines and the final average computation — no other formatting/prose changes.

…cise

The exercise reused a single average variable both to accumulate the
running sum of grades and to hold the final computed average. Splitting
these into sum and average makes the exercise and solution easier to
follow without changing behavior or output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant