Simvik

Countdown

Print inside a loop that counts down. An easy embedded C problem (Decisions and loops), run and graded in the browser.

easy · Decisions and loops · loops · printf

Print the numbers from n down to 1, each followed by a space, then the word liftoff and a newline.

For n equal to 3 the output is 3 2 1 liftoff. For 0 it is just liftoff.

Starter code

void countdown(int n) {
  printf("liftoff\n");
}

Example tests

From three

countdown(3);

Expected output:

3 2 1 liftoff

From one

countdown(1);

Expected output:

1 liftoff

Learn it first

  • Decisions and loops · Choosing with if and switch, repeating with while and for, and the loop that never ends.

More Decisions and loops problems