cybersecurity · beginner · ~15 min

Did every step succeed?

Aggregate the success of a sequence of calls.

Challenge

Confirm that every step in a sequence of operations succeeded, so a mid-chain failure can't be silently ignored.

Task

Implement int all_ok(const int *rcs, int n) that returns 1 if all n return codes are non-negative, else 0.

Input

  • rcs: an array of n return codes the grader passes.
  • n: the number of codes.

Output

Returns int: 1 if every rcs[i] >= 0, else 0.

Example

all_ok({0, 1, 2}, 3)    ->   1
all_ok({0, -1, 2}, 3)   ->   0   (one failure)

Edge cases

  • A single negative code makes the whole result 0 (fail-fast).

Input format

An int array rcs of length n.

Output format

An int: 1 if every code is >= 0, else 0.

Constraints

Any negative code yields 0.

Starter code

int all_ok(const int *rcs, int n) {
    /* TODO */
    return 0;
}

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