150 likes | 280 Views
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.
E N D
Buatalgoritmauntukmenampilkantulisanberikut: iteration number 1 iteration number 2 iteration number 3 iteration number 4 iteration number 5 after loop ends
Buatalgoritmauntukmenampilkan output berikut student no-1 is : student no-2 is : student no-3 is :
Buatalgoritmauntukmenerimainputantigabuahbilangan real, lalumenghitung rata-ratanya, danmenampilkanhasilnyakelayar
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.
The structure of the FOR-TO-DO statement FOR counter variableinitial_valueTO final_value program statement ENDFOR
START {initialize} Counter >= initial_value AND counter <= final_value ? action END Flowchart FOR-TO-DO No yes
Example 1 Flowchart START Pseudocode FOR x1 TO 5 DO output (x) ENDFOR x >=1 AND x <= 5 ? No yes output (x) END
Example 2 Pseudocode OUTPUT('before loop starts') FOR i = 1 TO 5 DO OUTPUT('iteration number ',i) ENDFOR OUTPUT('after loop ends')
Execution • generates the output
Example 3 FOR i 1 TO 5 DO Output (‘*’) {action statement} ENDFOR {end loop} The result of program : * * * * *
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 : __
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)