Practice Exercises
Practice modifying C++ code to print only odd or even multiples of a given number using loops. This lesson helps you apply basic programming concepts and enhances your skill in controlling program output.
We'll cover the following...
In this lesson, practice what we have learned so far by solving some challenges.
Printing odd multiples
Modify the program below so that only the odd multiples (1, 3, 5, 7 and so on) of the number are printed up to its 15th multiple.
So, for example, for the number 6, the odd multiples up to its 10th multiple would be:
6 x 1 = 6
6 x 3 = 18
6 x 5 = 30
6 x 7 = 35
6 x 9 = 54
Good luck!
If you have solved the problem, congratulations! π
Printing even multiples
Modify the program below so that only the even multiples (2, 4, 6, 8, and so on) of the number are printed up to the 16th multiple.
So, for example, for the number 6, the even multiples up to its 10th multiple would be:
6 x 2 = 12
6 x 4 = 24
6 x 6 = 36
6 x 8 = 48
6 x 10 = 60
Good luck! π
If you have solved the problem, congratulations!