Pemodelan untuk Komputasi: Nested Repetition dan Contoh Soal ( Bahasa Inggris )

Pemodelan untuk Komputasi: Nested Repetition dan Contoh Soal ( Bahasa Inggris )



Control Structures

Basically, different control structures can be combined in order to create a complex program, which is used to solve difficult problems : 
  • Nested If 
  • Combination of conditional & repetition 
  • Nested Repetition 



Nested Repetition: Pattern 1

Wombat Needs to Write this pattern :

@@@@@ 
@@@@@ 
@@@@@ 
@@@@@ 
@@@@@ 

To make the pattern, Wombat needs to: 
  • Write “@” symbol five times in a row 
  • Do step A five times to make five rows.

Algorithms for Pattern 1

First of all, write five @ symbols in a row :


Then, write five @ symbols in five rows : 


Then, combine the first step with second step that becomes right below :



Pattern 2


How about this one ?

@
@@
@@@
@@@@
@@@@@

To make the pattern, Wombat needs to: 

  • Write “@” symbol i times in a row, where i = row number
  • Do step A five times to make five rows.

Algorithms for Pattern 2

First, write @ symbols i times in a row, where i = row number: 


Second, write five @ symbols in five rows:



Pattern 3

Wombat wants to write n rows. In row number i, Wombat will write: Round i: number from 1 to i. Example (n = 5) 

Round 1: 1 
Round 2: 1 2 
Round 3: 1 2 3 
Round 4: 1 2 3 4 
Round 5: 1 2 3 4 5

To make the pattern, Wombat needs to:
  • Write “Round i: 1 to i" in each row, where i is row number.
  • Do step 1 n times to make n rows.

Algorithms for Pattern 3

First, write "Round i: 1 to i" in each row, where i is row number. 



Second, do step A n times to make n rows. 




Exercise 1



Wombat wants to write this pattern: (example if n = 5) 

Round 1: 1 1 1 1 1 
Round 2: 2 2 2 2 2 
Round 3: 3 3 3 3 3 
Round 4: 4 4 4 4 4 
Round 5: 5 5 5 5 5 


Exercise 2


Wombat wants to write this pattern. Example if n = 5: 

Round 1: 5 5 5 5 5 
Round 2: 4 4 4 4 4 
Round 3: 3 3 3 3 3 
Round 4: 2 2 2 2 2 
Round 5: 1 1 1 1 1


Exercise 3

Wombat wants to write this pattern: (example if n = 5)

Round 1: 5 5 5 5 5
Round 2: 4 4 4 4 
Round 3: 3 3 3
Round 4: 2 2
Round 5: 1

Post a Comment

Lebih baru Lebih lama