Given an integer n> 0, write a recursive function countDown that writes the integers n, n – 1, . . . , 1. Hint: What task can you do and what task can you ask a friend to do for you?

What will be an ideal response?


```
// Precondition: n > 0.
// Postcondition: Writes n, n - 1, ... , 1.
void countDown(int n)
{
if (n > 0)
{
cout << n << endl;
countDown(n-1);
} // end if
} // end countDown

```

Computer Science & Information Technology

You might also like to view...

Revise the program in number 8 above to use a try/catch block to handle the IOException.

What will be an ideal response?

Computer Science & Information Technology

Which one of the following objects allows users to add data to the database?

A) Query B) Table C) Record D) Form

Computer Science & Information Technology

Testing  that validates a program by ensuring that all of its statements have been executed-that is, by knowing exactly how the program is written-is ____.

A. Blackbox testing B. Destructive testing C. Nondestructive testing D. System testing E. Whitebox testing

Computer Science & Information Technology

Which of the following statements about streams is false?

A. A stream is a source of, or destination for, data B. A binary stream consists of a sequence of data values such as integer C. A text stream consists of a sequence of characters terminated by newlines D. Because text streams can contain only characters, we cannot send integer data to them E. Because binary streams can store any type of data, we can send real data to them

Computer Science & Information Technology