KEMBAR78
Introduction To Algorithm [2] | PPT
Programming & Algorithm Introduction to Algorithm January , 2008
What is Algorithm? Algorithm: Steps that are needed for solving a  problem. E.g.: Playing Blackjack algorithm Pick two cards. Is the score ≤ 15? Yes : pick one card and return to number 2. No : Open the cards.
The Algorithm Components 1 : Program Hitung_Kuadrat 2 : Kamus 3 : a, b : number 4 : function kuadrat (a: integer) -> integer 5 : Algoritma 6 : {input nilai a} 7 : input(a) 8 : 9 : {menghitung kuadrat dari a} 10 : b ← kuadrat(a) 11 : output(b) 12 : 13 : {fungsi yang menghitung kuadrat} 14 : function kuadrat (a: integer) -> integer 15 : 16 : Kamus lokal 17 : 18 : Algoritma 19 : -> a*a
The Algorithm Components Program, function, procedure name (Lines 1, 14). Variable definition (Line 3) Function Prototype (Line 4) Algorithm (Lines 5-11, 18-19) Program statements (Lines 7, 10, 11, 19) input(a) b ← kuadrat(a) output(b) ->  a*a Function definition (Lines 14-19) Algorithm comments (Lines 6, 9, 13)
Variables Variable is a named data storage. Variable names must adhere to the following rules: The name can contain letters, digits, and the underscore (_). The first character of the name must be a letter. Case matters. Keywords cannot be used as variable names.
Numeric Variable Types Numeric variable fall into two main categories: Integer variables  hold values that have no fractional part. Float variables  hold values that have a fractional part (that is, real numbers).
Variable Declarations A variable declaration has the following form: Kamus var_name: type_name
Constants Use  const  keyword for defining a constant. E.g.: Kamus const  constname  :  consttype  ←  literal
Expressions An expression is anything that evaluates to a value. Simple Expressions: a simple variable, literal constant, or symbolic constant. Complex Expressions: simpler expressions connected by operators.
Operators Assignment operator (←) Mathematical operators  (+, -, /, div, *, mod ) Relational operators (>, ≥, <, ≤, =, ≠) Logical operators (and, or, not)

Introduction To Algorithm [2]

  • 1.
    Programming & AlgorithmIntroduction to Algorithm January , 2008
  • 2.
    What is Algorithm?Algorithm: Steps that are needed for solving a problem. E.g.: Playing Blackjack algorithm Pick two cards. Is the score ≤ 15? Yes : pick one card and return to number 2. No : Open the cards.
  • 3.
    The Algorithm Components1 : Program Hitung_Kuadrat 2 : Kamus 3 : a, b : number 4 : function kuadrat (a: integer) -> integer 5 : Algoritma 6 : {input nilai a} 7 : input(a) 8 : 9 : {menghitung kuadrat dari a} 10 : b ← kuadrat(a) 11 : output(b) 12 : 13 : {fungsi yang menghitung kuadrat} 14 : function kuadrat (a: integer) -> integer 15 : 16 : Kamus lokal 17 : 18 : Algoritma 19 : -> a*a
  • 4.
    The Algorithm ComponentsProgram, function, procedure name (Lines 1, 14). Variable definition (Line 3) Function Prototype (Line 4) Algorithm (Lines 5-11, 18-19) Program statements (Lines 7, 10, 11, 19) input(a) b ← kuadrat(a) output(b) -> a*a Function definition (Lines 14-19) Algorithm comments (Lines 6, 9, 13)
  • 5.
    Variables Variable isa named data storage. Variable names must adhere to the following rules: The name can contain letters, digits, and the underscore (_). The first character of the name must be a letter. Case matters. Keywords cannot be used as variable names.
  • 6.
    Numeric Variable TypesNumeric variable fall into two main categories: Integer variables hold values that have no fractional part. Float variables hold values that have a fractional part (that is, real numbers).
  • 7.
    Variable Declarations Avariable declaration has the following form: Kamus var_name: type_name
  • 8.
    Constants Use const keyword for defining a constant. E.g.: Kamus const constname : consttype ← literal
  • 9.
    Expressions An expressionis anything that evaluates to a value. Simple Expressions: a simple variable, literal constant, or symbolic constant. Complex Expressions: simpler expressions connected by operators.
  • 10.
    Operators Assignment operator(←) Mathematical operators (+, -, /, div, *, mod ) Relational operators (>, ≥, <, ≤, =, ≠) Logical operators (and, or, not)