st05-flow_control_2

st05-flow_control_2 - CSC 1111 Introduction to Computing...

This preview shows pages 1–6. Sign up to view the full content.

1 CSC 1111 Introduction to Computing using C++ for loop and nested loop, break and continue

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 for Loop (Exercise) Using a for loop to perform each of these tasks: 1. Print all odd numbers in reverse order from N to 1. (N can be and odd or even number) 1. Print 1, 4, 7, 10, 13, 16, . .., 100 1. Calculate sum of the first N positive integers 1. Print 1, 2, -3, -4, 5, 6, -7, -8, 9, 10, …, -99, -100 1. Calculate 1 2 – 2 2 + 3 2 – 4 2 + … + 99 2 – 100 2
3 Nested Loop What's the output produced by the following segment of code? for (int i = 10; i > 0; i--) for (int j = 0; j < i; j++) cout << i << " " << j << endl;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Nested Loop Print an N by N (1 ≤ N ≤ 19) table containing integers from 1 to N 2 row by row. Each number is right aligned in an invisible cell of 4 characters wide. e.g. When N = 5, the output should look like 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
5 Nested Loop Print an N by N (1 ≤ N ≤ 19) table containing integers from 1 to N

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 14

st05-flow_control_2 - CSC 1111 Introduction to Computing...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online