Physics and Astronomy
Home Our Teaching Resources C programming Exercises
Contents

These form an important part of your learning but are not formally assessed as a part of your course mark. Bring them to a demonstrator next week for feedback.

## Exercise using switch()

• Take a copy of last week's Fizz buzz program and modify it so it uses the switch() statement.

## Loop exercises

### Every even number

• Write a loop that prints every even number from zero to 20.
• Now modify your program to have a limit which should be an int variable with a value assigned to it before the loop and continue the loop as long as the number is less than twenty or its square root is less than the value.
• Now modify your code again so that the limit has the values 50, 100, 150, ... etc ..., 950, 1000 by using a loop within a loop.

### Fizz buzz in a loop

• Take a copy of one of your fizz-buzz games either from the previous exercise or from last week and modify it to play the game for the numbers 1 to 30 inclusive using a loop rather than reading the numbers from the keyboard.
• Now modify it so it counts downwards from 30 to 1.