Tutorial 5 Arrays Basics 1 D 2 D

Tutorial 5 Arrays Basics (1 D, 2 D) NUS SCHOOL OF COMPUTING CS 1010 E PROGRAMMING METHODOLOGY CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 1

Quick Summary CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 2

Question 1: Tracing Arrays CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 3

Question 1: Tracing Arrays pass. Element(int num) List 1 11 22 33 44 55 List 2 99 99 99 CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO num 11 num 1234 4
![Question 1: Tracing Arrays change. Elements(int list[]) List 1 11 22 33 44 55 Question 1: Tracing Arrays change. Elements(int list[]) List 1 11 22 33 44 55](http://slidetodoc.com/presentation_image_h2/e54c40325e9429878cfdd00e28af4dc4/image-5.jpg)
Question 1: Tracing Arrays change. Elements(int list[]) List 1 11 22 33 44 55 List 2 99 99 99 77 99 88 99 CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 5

Question 1: Tracing Arrays copy. Array(list 2, list 1, 5) List 1 11 22 33 44 55 List 2 99 11 99 22 77 33 99 44 88 55 CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 6

Question 2: Sieve Prime Numbers CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 7

Question 2: Sieve Prime Numbers CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 8

Question 2: Sieve Prime Numbers Find the next Prime Number Use for loop to eliminate all the multiples of the prime number CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 9

Question 2: Sieve Prime Numbers CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 10

Question 3: Pascal Triangle CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 11

Question 3: Pascal Triangle Element: Up CS 1010 E TUTORIAL SLIDES Element: Up. Left PREPARED BY WU CHAO 12

Question 3: Pascal Triangle Question: is it possible to fill up the triangle without considering the border values? Yes, we could initialize all the elements in the Pascal Triangle (2 D Array) to 1 first. And our index starts from 1 instead of 0. CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 13

Question 3: Pascal Triangle CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 14

Question 3: Pascal Triangle CS 1010 E TUTORIAL SLIDES PREPARED BY WU CHAO 15
- Slides: 15