0% found this document useful (0 votes)
139 views4 pages

CSC425 Exercise 7 Looping 1

The document discusses repetition structures in C++ programs. It provides examples of for loops to print numbers in a range and check for even/odd values. It lists tasks for students to write programs using for loops, including having the user enter 10 numbers and calculating totals, averages, and even/odd counts. The final task is for students to practice additional examples from lecture notes.

Uploaded by

nady
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views4 pages

CSC425 Exercise 7 Looping 1

The document discusses repetition structures in C++ programs. It provides examples of for loops to print numbers in a range and check for even/odd values. It lists tasks for students to write programs using for loops, including having the user enter 10 numbers and calculating totals, averages, and even/odd counts. The final task is for students to practice additional examples from lecture notes.

Uploaded by

nady
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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