Logika dan Algoritma pemrograman

  • View
    228

  • Download
    11

  • Category

    Software

Preview:

Citation preview

Logika & AlgoritmaPemrograman

● Android Developer di qiscus● Penulis buku “Livecoding! 9 Aplikasi Android

Buatan Sendiri”● omayib@gmail.com (email) | @omayib

(Twitter)

“jika pelukis memilki kanvas untuk mencurahkan imajinasinya,Maka programmer punya RAM yang bisa di manipulasi sesuai

imajinasi”

Arif Akbarul Huda

Peanut Butter Robo Game

Singapore, March 2014

They are learn about

● Instruction● logic

What is programming?

● Series of instruction to a computer to accomplish a task

● Group of instruction will make a program to perform that particular task

How to give instruction to Computer

Abcdefghaij blblblabla01100110001

Programming languange

What is Algorithms?

● List of step● Like the instruction for a recipe● Used for solving specific task or problem

Sample taskTask : add two number

Algorithm :

Step 1: Start

Step 2: Declare variables num1, num2 and sum.

Step 3: Read values num1 and num2.

Step 4: Add num1 and num2 and assign the result to sum.

sum←num1+num2

Step 5: Display sum

Step 6: Stop

What is flowchart looks like?

start

Get two number

Calculate both number

Show the result

finish

What are symbols?

http://www.smartdraw.com/flowchart/flowchart-symbols.htm

Wich is the oldest?

Nabila17 old

Vina12 old

Feyza15 old

Wich is the oldest?

Step 1: StartStep 2: Declare variables a,b and c.Step 3: Read variables a,b and c.Step 4: If a>b If a>c Display a is the largest number. Else Display c is the largest number. Else If b>c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop

What is the flowchart look like?start

Get input as a, b, c

a>b

C as the oldestb>c

a>c A as the oldesty y

nn

B as the oldest

y

n

finish

How does human perform simple task?

Add 345 and 155

500!

1. She hear it trough input sense

2. Store the number 345 and 155 in his memory

3. Calculate those number in his brain and store the result in memory

4. She say the result trough output sense

How does computer perform simple task?

1. Computer use keyboard to receive input

4. Computer user monitor to display output

3. Camputer calculate both number using CPU (with ALU inside) and

store back in RAM

2. Computer store the number 345 and 155 in RAM

Element of Programming

Write all number 1-100

start

i=1

i<=100? Print i

i++

stop

● During programming, we my need to do following– Store data temporarily

– Control the normal flow of instruction

– Repeat one or more instruction several time

– Repeat group of instruction at several parts of program

http://www.slideshare.net/BaabtraMentoringPartner/algorithms-introduction-to-computer-programming on slide 48

● During programming, we my need to do following– Store data temporarily (variable)

– Control the normal flow of instruction (Decission)

– Repeat one or more instruction several time (Loops)

– Repeat group of instruction at several parts of program (Function)

http://www.slideshare.net/BaabtraMentoringPartner/algorithms-introduction-to-computer-programming on slide 48

variables

Write all number 1-100

start

i=1

i<=100? Print i

i++

stop

● Place to put data or value● Presented by letter or a word● Variable name can't contain space● Some of data types are String, Int, Boolean, Float● Example (java)

● int TOTAL_NUM = 10;● String city=””;

DECISSION

Write all number 1-100

start

i=1

i<=100? Print i

i++

stop

● A program often needs to decide wheter something is true or

false in order to see which way to continue

● Also called conditional statement

● if...else

● Switch...case

LOOP

Write all number 1-100

start

i=1

i<=100? Print i

i++

stop

● a loop is a sequence of instruction s that is continually repeated

until a certain condition is reached

● A loop often has a counter and continues to repeat a specified

number of times

● Some type of loop in programming

● For..

● While

● do...while

FUNCTION

start

finish start

i=1

i<=100? Print i

i++

stop

● In most programming language, small sub-programs are

used to perform some of the task

● Functions usually "take in" data, process it, and "return" a result

● Once a function is written, it can be used over and over and

over again

● Functions can be "called" from the inside of other functions.

Recommended