st05-flow_control_2

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

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

View Full Document Right Arrow Icon
1 CSC 1111 Introduction to Computing using C++ for loop and nested loop, break and continue
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 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;
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
5 Nested Loop Print an N by N (1 ≤ N ≤ 19) table containing integers from 1 to N
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 Right Arrow Icon
Ask a homework question - tutors are online