Find the error(s) in each of the following program segments, and explain how the error(s) can be corrected :

```
int sum(int n) { // assume n is nonnegative if (0 == n)
return 0;
else
n + sum(n - 1);
}
```

Error: The result of n + sum(n - 1) is not returned; sum returns an improper result.
Correction: Rewrite the statement in the else clause as
```
return n + sum(n - 1);
```

Computer Science & Information Technology

You might also like to view...

The most common means of making entries in the general ledger is via the journal voucher.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

A _____ is responsible for assigning maintenance tasks to individuals or to a maintenance team.

A. tester B. programmer C. system validator D. system administrator

Computer Science & Information Technology