Repetition C

Repetition C : Pengulangan, looping

Looping operation (repetition)

-) for : kondisinya bisa dikosongin

-) While : kondisinya harus ada isi dan sebelum buat statement kondisi harus di cek dulu

-) Do.while : membuat kondisi dahulu baru di cek [ (isi dulu) baru jalanin ]

Repetition : for

For (exp1; exp2; exp3;) statement;

Or

For ( exp1; exp2; exp3;){

Statement 1;

Statement 2;

………………

}

 

Exp1; initialization

Exp2; conditional

Exp3; increament or decrement

Mau 3”nya dihilangkan / tidak dihilangin tetap looping forever

Break: untuk memberhentikan looping

Continue : skip

 

While

Akan berjalan jika kondisinya TRUE

Tidak akan berjalan jika kondisinya FALSE

Kelebihan : bisa jalan dengan syarat ≠ 0 jadi selalu benar jika kondisinya benar

Do While

Terus berjalan selama exp True, statement berjalan dahulu baru mengecek kondisi

Selection

Selection

Syntax :

-) if

-) if-else

-) Switch Case

Syntax if (boolean Expression) statement

Or

It (boolean expression) {

Statement 1

Statement 2

}

Kata Cuma 1 statement boleh ga pakai {}

If else

Syntax:

If (boolean expression) statement

Else statement 2;

Or

If (boolean expression) {

Statement 1

Statement 2

}

Else {

Statement 3

Statement 4

}

 

 

 

 

 

Nested – if

Bersifat harus melalui seleksi

If ( boolean expression ) statement;

Else

If ( boolean expression statement 2;

Else

If ( boolean expression statement 3;

Switch – case

Tidak harus bersifat True or false bisa juga berupa data, nilai {sifat expression}

Syntax

Switch (expression) {

Case contant 1 : statement 1 : break :

.

.

Case contant 2 : statement 2 ; break ;                                                                                                                                                     default : statement:

.

}

Wajib di break supaya tidak turun ke bawah

If terdapat 2 nilai : True

False

While              T

% d int         10        0-9

% 0 octal       8        0-7

%x%x hexa 16        0-9

 

 

 

 

 

 

 

 

Operator Introduction

Operator Introduction

Operator

Operand

C = A+B → Binary ada + =

  • % (modulus)

*

/

 

Operation number 3 :

Unary Operator → 1 operand

Binary Operator → 2 operand

Temary Operand → 3 operand

Operation type 6 group :

  • Assignment → nilai variabel X = 3 (operand 1 = operand 2)
  • Logical
  • Arithmetic → + − * / % ++ −− ()
  • Relational
  • Bitwise
  • Pointer

 

N ++ : // post increament

+ NN : // pre increament

N −−  : // post decreament

−− N : // pre decrement

 

Expression                            combined operator

A = a + b;                               a + = b;

A = a – b;                               a – = b;

 

Relational

= =   → Equality

! =    → Not Equal

<      → Less than

>      → Greater than

< =   → Less or equal then

> =   → Greath or equal then

? =   → Conditional statement

1 = T   X = ( 20 > 10 ) ; (1)

0 = f    X = ( 20 > 10 ) ; (1)

 

Conditional expressions

If ( a > b ) Z = a;

Else Z = b ;

Z = ( a > b ) ? a : b ;

A = 5                 Z = 3                           benar               Z = a

B = 3                                                     salah         Z≠ b

A = 3                Z =7

B = 5

 

Logical Operator

Symbol Functionally
&& AND
|| OR
| NOT

 

P Q Xor → a|b & ! (a & b)
T T F
T F T
F T T
F F F

 

Logical operators

Int X = 5 , int Y = 0 ;

X && Y;                        // FALSE               0

(X > Y ) && ( Y >= 0 )   // TRUE ≠ 0

 

Bitwise

Symbol Meaning Example
& AND A & B
| OR A|B;
˄ XOR A˄B;
˜ Complement ˜A;
>> Shiftt right A>>3;
<< Shift left B<<2,

 

EX:

10 : itu berapa bit

Cari 2n yang lebih kecil dari 10
n = 3

23      22     21    20

_      _     _     _

 

15 itu berapa bit

23  :  ˄ = 3

1       1     1     1

__   __   __   __

15 – 8 = 7 = 23 = 3 – 21  = 1

 

37 = 25

1      0      0      1      0    1

__    __   __   __   __   __                                                  37 – 25  = 5 – 22 = 1- 20 = 0

25   24   222 220                 

I I = ( 100 – 1 )

I I I = ( 1000 – 1 )

I I I I I I = 63

( 100000 ) – 1

64 -1 = 63

 

Bit wise = yang dioperasikan Bitnya

4 = 100                4 = 100

3 = 011               5 = 011

0 = 000               1 = 111

int A,B = 78

A = B >> 3 ; // Value A = 9

A = B << 2 ; // Value A = 312

78, binary : 0100 1110

First shift      : 0010 0111

Second shift : 0001 0011

Third shift     : 0000 1001               9 decimal

Operator Introduction

Operator

Operand

C = A+B → Binary ada + =

  • % (modulus)

*

/

 

Operation number 3 :

Unary Operator → 1 operand

Binary Operator → 2 operand

Temary Operand → 3 operand

Operation type 6 group :

  • Assignment → nilai variabel X = 3 (operand 1 = operand 2)
  • Logical
  • Arithmetic → + − * / % ++ −− ()
  • Relational
  • Bitwise
  • Pointer

 

N ++ : // post increament

+ NN : // pre increament

N −−  : // post decreament

−− N : // pre decrement

 

Expression                            combined operator

A = a + b;                               a + = b;

A = a – b;                               a – = b;

 

Relational

= =   → Equality

! =    → Not Equal

<      → Less than

>      → Greater than

< =   → Less or equal then

> =   → Greath or equal then

? =   → Conditional statement

1 = T   X = ( 20 > 10 ) ; (1)

0 = f    X = ( 20 > 10 ) ; (1)

 

Conditional expressions

If ( a > b ) Z = a;

Else Z = b ;

Z = ( a > b ) ? a : b ;

A = 5                 Z = 3                           benar               Z = a

B = 3                                                     salah         Z≠ b

A = 3                Z =7

B = 5

 

Logical Operator

Symbol Functionally
&& AND
|| OR
| NOT

 

P Q Xor → a|b & ! (a & b)
T T F
T F T
F T T
F F F

 

Logical operators

Int X = 5 , int Y = 0 ;

X && Y;                        // FALSE               0

(X > Y ) && ( Y >= 0 )   // TRUE ≠ 0

 

Bitwise

Symbol Meaning Example
& AND A & B
| OR A|B;
˄ XOR A˄B;
˜ Complement ˜A;
>> Shiftt right A>>3;
<< Shift left B<<2,

 

EX:

10 : itu berapa bit

Cari 2n yang lebih kecil dari 10
n = 3

23      22     21    20

_      _     _     _

 

15 itu berapa bit

23  :  ˄ = 3

1       1     1     1

__   __   __   __

15 – 8 = 7 = 23 = 3 – 21  = 1

 

37 = 25

1      0      0      1      0    1

__    __   __   __   __   __                                                  37 – 25  = 5 – 22 = 1- 20 = 0

25   24   222 220                 

I I = ( 100 – 1 )

I I I = ( 1000 – 1 )

I I I I I I = 63

( 100000 ) – 1

64 -1 = 63

 

Bit wise = yang dioperasikan Bitnya

4 = 100                4 = 100

3 = 011               5 = 011

0 = 000               1 = 111

int A,B = 78

A = B >> 3 ; // Value A = 9

A = B << 2 ; // Value A = 312

78, binary : 0100 1110

First shift      : 0010 0111

Second shift : 0001 0011

Third shift     : 0000 1001               9 decimal

Ringkasan Algoritma dan Pemrograman

JAVA

OOP merupakan kepanjangan dari Object Oriented Progamming

End capsulation: teknik privatisasi bersifat private bisa juga untuk public

Abstraction: bersifat wajib (contoh: wajib meneruskan keturunan dari kedua orang tuanya)

Interface: berssifat bisa lebih dari 1 (boleh pinjam)

Polymerism: menggunakan method dengan bijak efesien

Inherter: bersifat tidak wajib (contoh: Bapak dengan anak, tidak wajib, sifat bapak pada anak tidak harus ditunjukkan dan anak bisa melakukan sifatnya sesuai keturunan bisa juga melakukan perubahan.

NO SQL adalah membaca dan mengenali storage

ALGORITMA

  • Pseudo Code = tulisan
  • Flow Chart = aliran berupa data/gambar (Start End)

Source Code = bahasa pemograman

Executable Code = bahasa machine

Compile

Syntax Error

Testing

Outputer = problem defination

Documention

Pseudo code terbagi 3 :

  • Input
  • Process (compile, store, compare, loop)
  • Output

Structure Theorem

Procuderal = Structure

Striucture terbagi 3:

  • Sequence = urutan
  • Selection = if else
  • Repetition/loop(downwhile)

C terbagi atas 4 :

  • Flexibility
  • Portability
  • Well – known
  • Supported with large libraries

C structure

  • Main = utama
  • Case sensitive
  • Every statement should be with ; semi colon

4 jenis 

  • Comment : (|* */) & (//)
  • Keyword
  • Data
  • Variable