14
PEMROGRAMAN KOMPUTER Basic of Algorithm Christyowidiasmoro, ST:, MT., MSc.

# Algoritma %26 Pemrograman Komputer - Basic Algorithm

091111

• View
227

0

Embed Size (px)

Citation preview

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

PEMROGRAMAN KOMPUTERBasic of Algorithm

Christyowidiasmoro, ST:, MT., MSc.

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

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

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

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

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

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

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

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

Discussion

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

{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

Discussion

A B C

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

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

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

{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 . : :