tutorial 5 arrays basics (1d, 2d) nus school of computing cs1010e programming methodology 1 cs1010e...
TRANSCRIPT
1
Tutorial 5 Arrays Basics (1D, 2D)
NUS SCHOOL OF COMPUTING
CS1010E PROGRAMMING METHODOLOGY
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
2
Quick Summary
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
3
Question 1: Tracing Arrays
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
4
Question 1: Tracing Arrays
List1 11 22 33 44 55List2 99 99 99 99 99
num 11
passElement(int num)
num 1234
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
5
Question 1: Tracing Arrays
List1 11 22 33 44 55List2 99 99 99 99 99
changeElements(int list[])
77 88
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
6
Question 1: Tracing Arrays
List1 11 22 33 44 55List2 99 99 77 99 88
copyArray(list2, list1, 5)
11 22 33 44 55
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
7
Question 2: Sieve Prime Numbers
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
8
Question 2: Sieve Prime Numbers
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
9
Question 2: Sieve Prime Numbers
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
Find the next Prime Number
Use for loop to eliminate all the multiples of the prime number
10
Question 2: Sieve Prime Numbers
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
11
Question 3: Pascal Triangle
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
12
Question 3: Pascal Triangle
Element: Up
Element: UpLeft
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
13
Question 3: Pascal TriangleQuestion: is it possible to fill up the triangle without considering the border values?
Yes, we could initialize all the elements in the Pascal Triangle (2D Array) to 1 first. And our index starts from 1 instead of 0.
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
14
Question 3: Pascal Triangle
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO
15
Question 3: Pascal Triangle
CS1010E TUTORIAL SLIDES PREPARED BY WU CHAO