Countdown

This is a warmup exercise. It is not compulsory, and may be completed individually or with your lab partner.

We use loops in C to do things multiple times. Here is an exmaple of a loop that prints all the numbers from 1 to 17 on a new line in ascending order:

int counter = 1; //initialise counter to 1
while (counter <= 17) { // loop until not <= 17
    printf("%d\n", counter); // print counter
    counter = counter + 1; // increment counter
}

In this exercise you will use a loop to print a countdown from 10 to 0. Start by creating a file called countdown.c in your week 4 directory, and copying the above code. Modify this code so that the loop counts down from 10 until 0.

Example

$ ./countdown
10
9
8
7
6
5
4
3
2
0

To run some simple automated tests:

$ 1511 autotest countdown

To run Styl-o-matic:

$ 1511 stylomatic countdown.c
Looks good!

You’ll get advice if you need to make changes to your code.

Submit your work with the give command, like so:

$ give cs1511 wk04_countdown

Or, if you are working from home, upload the relevant file(s) to the wk04_countdown activity on Give Online.