1 / 15

Latihan

Latihan. Buat algoritma untuk menampilkan output berikut : * * * * *. Buat algoritma untuk menampilkan tulisan berikut : iteration number 1 iteration number 2 iteration number 3 iteration number 4 iteration number 5 after loop ends.

Télécharger la présentation

Latihan

An Image/Link below is provided (as is) to download presentation Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript

1. Latihan

2. Buatalgoritmauntukmenampilkantulisanberikut: iteration number 1 iteration number 2 iteration number 3 iteration number 4 iteration number 5 after loop ends

3. Buatalgoritmauntukmenampilkan output berikut student no-1 is : student no-2 is : student no-3 is :

4. Buatalgoritmauntukmenerimainputantigabuahbilangan real, lalumenghitung rata-ratanya, danmenampilkanhasilnyakelayar

5. Write the algorithm to calculate cost of electricity with following constraints : (KWHs) Rate 0 - 500 2000 501 - 1000 2000 + 0.03 * per KWH over 1001 3500 + 0.02 * per KWH Enter the values of previous month meters, current month meter, and then displays the total cost which would exist.

6. The structure of the FOR-TO-DO statement FOR counter variableinitial_valueTO final_value program statement ENDFOR

7. START {initialize} Counter >= initial_value AND counter <= final_value ? action END Flowchart FOR-TO-DO No yes

8. Example 1 Flowchart START Pseudocode FOR x1 TO 5 DO output (x) ENDFOR x >=1 AND x <= 5 ? No yes output (x) END

9. Example 2 Pseudocode OUTPUT('before loop starts') FOR i = 1 TO 5 DO OUTPUT('iteration number ',i) ENDFOR OUTPUT('after loop ends')

10. Execution • generates the output

11. Example 3 FOR i  1 TO 5 DO Output (‘*’) {action statement} ENDFOR {end loop} The result of program : * * * * *

12. Example 4 • Program with enter the value of 3 student’s scores : Pseudocode FOR i  1 TO 3 DO Output (‘Score student no-‘,i,’ is:’) Input (score) ENDFOR • Execution : • Score student no-1 is : __ • Score student no-2 is : __ • Score student no-3 is : __

13. Example 5 • Average of 3 numbers number  0 {initialize} FOR i  1 TO 3 DO Input (x) {input value of x} number  number + x {sum of x variables} ENDFOR average  number/ 3 {calculate the average} Output (average)

More Related