Exercises on Control Flow
Explore fundamental control flow techniques in C by solving practical exercises like FizzBuzz, Newton’s method for square roots, and triangle display. Learn to use loops, conditionals, and switch statements to control program logic and enhance your coding fluency.
We'll cover the following...
We'll cover the following...
The solutions for the exercises are included in the solution tabs. For best learning outcomes, don’t look at these unless you’ve attempted the problems yourself.
Question 1: FizzBuzz
Write a program that prints the numbers from 1 to 100 with the following exceptions:
- For multiples of 3, print ‘Fizz’ instead of the number.
- For multiples of 5, print ‘Buzz’ instead of the number.
- For numbers that are multiples of both 3 and 5, print ‘FizzBuzz’ instead.
Try solving here:
Question 2: Newton’s method
Write a program to estimate the square root of 612 using Newton’s method, using five iterations.
Try solving here: