cybersecurity · beginner · ~15 min · safe pentest lab

Total evidence size

Sum a list of sizes.

Challenge

Add up the sizes of the files going into an evidence bundle, so you can later check the total against a transfer limit.

Task

Implement long total_size(const int *sizes, int n) that returns the sum of the first n entries of sizes.

Input

  • sizes: an array of file sizes the grader provides.
  • n: the number of entries to sum (may be 0).

Output

Returns the sum of the n sizes, as a long.

Example

total_size({100, 200, 50}, 3)   ->   350
total_size({100, 200, 50}, 0)   ->   0

Edge cases

  • n == 0: returns 0.

Rules

  • Accumulate into a long to avoid int overflow on large bundles.

Input format

An array of file sizes and a count n (may be 0).

Output format

The sum of the first n sizes, as a long.

Constraints

Accumulate into a long; n == 0 gives 0.

Starter code

long total_size(const int *sizes, int n) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.