Algoritma %26 Pemrograman Komputer - Basic Algorithm

Post on 10-Apr-2018

227 views 0 download

Transcript of Algoritma %26 Pemrograman Komputer - Basic Algorithm

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 1/14

 PEMROGRAMAN KOMPUTERBasic of Algorithm

Christyowidiasmoro, ST:, MT., MSc.

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 2/14

Se uence 

Given chicken soup in bowl A and seafood

and bowl B so that bowl A contains seafood

soup and bowl B contains chicken soup.

1. Pour the content of bowl A into bowl C.

2. Pour the content of bowl B into bowl A.

 . .

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 3/14

Selection If Budi wins the com etition

then father will buy him a bicycle. 

then I will take a left turn to Kartini Street.

 

else you will go by taxi.

 else if  it is yellow then you must drive carefully elseif  it is reen ou can o ahead. 

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 4/14

Re etition Writin 10 Sentences

Writing “I will not cheat in the exam”.

1. Write “I will not cheat in the exam”.

2. Write “I will not cheat in the exam”.3. Write “I will not cheat in the exam”.

……….

 . r te w not c eat n t e exam .10. Write “I will not cheat in the exam”.

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 5/14

Re etition= ++

Write “I will not cheat in the exam”;

n = 1  w e n

Write “I will not cheat in the exam”;

 n = n + 1;

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 6/14

In ut and Out ut

 

input from user and it also needs to print the.

  xamp e: eating a gorit m nee s t e user to

enter the total number of sentences and it

nee s to pr nt t e sentences.

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 7/14

How to Write an Al orithmAl orithm NAME_OF_ALGORITHM

{ Write the explanation of the algorithm, whatthe algorithm does. }

DECLARATIONr e a ype, cons an s, var a es, anfunction that will be used in the algorithm. }

DESCRIPTIONWrite all the ste action in the al orithm.

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 8/14

Exam leAlgorithm AREA_OF_CIRCLE

{ Given the radius of a circle, this algorithm calculate thearea of the circle. }

DECLARATION

r = the radius of the circle;L = area of the circle;

π = 3.14;

DESCRIPTION

L = π*r2

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 9/14

Discussion 

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 10/14

AnswerAlgorithm SOLVE_EQUATION

{this algorithm is used to solve the given equation. }

DECLARATION

= oa , ou pu o e equa on

a, b, c =float, input of the equation;

d, e, f, g =float, temporary variables;

DESCRIPTION

1. d = (b*b) – (4*a*c)

= *.

3. f = -b +4

4. g = f / (a*a*a)

 .

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 11/14

Discussion

A B C

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 12/14

Discussion 

disks were inserted into an iron stick A so thatthe larger disk was placed under the smallerone.

Write an algorithm to move the disks into stickB. In every step there only be one disk to move,

and the larger disk cannot be placed on top ofthe smaller one.

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 13/14

Quiz 

from second unit into hours, minutes, and seconds.

Output: 

Input:5000 seconds

rocess

????

 Minutes = 23Seconds = 20

8/8/2019 Algoritma %26 Pemrograman Komputer - Basic Algorithm

http://slidepdf.com/reader/full/algoritma-26-pemrograman-komputer-basic-algorithm 14/14

AnswerAlgorithm CONVERT_SECOND_TO_TIME

{this algorithm is used to convert a given second to HH:MM:SS format. }

DECLARATION

s = integer, input

hh, mm, ss = integer, output;

DESCRIPTION

1. hh = s / 3600

2. s = s % 3600

3. mm = s / 60

4. ss = s % 60 . : :