You are on page 1of 4

CSC425

Exercise 7: Selection Structure Part 3 - Repetition.

Task 1: Trace the output for the following program segment.

a.

b.

c.

d. for (int num = 1; num <= 20; num = num + 2)


{
cout << num << ;
count+=1;
}
cout << \nThere is << count << numbers. << endl;

e. for (int num = 30; num >= 0; num = num - 5)


{
if (num % 2 == 0)
cout << num << is even number. << endl;
else
cout << num << is odd number. << endl;
}
Task 2:

Task 3:
Task 4:

Write a complete C++ program that allows the user to print the following message 10 times.
The message is I can do it!

Task 5:

Write a complete C++ program that allows the user to enter 10 numbers. Your program is able
to calculate the total and average of these numbers. Display the total and average to the user.

The example of output:


Task 6:

Write a complete C++ program that allows the user to enter 10 numbers. Your program is able
to do the following tasks:
a. Calculate the number of even numbers;
b. Calculate the number of odd numbers;

This is the sample of output:

Task 7: Try all the programs in the lecture notes.

You might also like