cybersecurity · beginner · ~15 min · safe pentest lab
Sum a list of sizes.
Add up the sizes of the files going into an evidence bundle, so you can later check the total against a transfer limit.
Implement long total_size(const int *sizes, int n) that returns the sum of the first n entries of sizes.
sizes: an array of file sizes the grader provides.n: the number of entries to sum (may be 0).Returns the sum of the n sizes, as a long.
total_size({100, 200, 50}, 3) -> 350
total_size({100, 200, 50}, 0) -> 0
n == 0: returns 0.long to avoid int overflow on large bundles.An array of file sizes and a count n (may be 0).
The sum of the first n sizes, as a long.
Accumulate into a long; n == 0 gives 0.
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.