teori materi 4 algoritma dan pemrograman ii.ppt€¦ · microsoft powerpoint - teori materi 4...
TRANSCRIPT
![Page 1: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/1.jpg)
Penyeleksian Kondisi
• if
• if else
• if else if
• switch
![Page 2: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/2.jpg)
if
if (EXPRESSION)
Statement;
Next_statement;
OROR
if (EXPRESSION)
{
Statement;
}
Next_statement;
![Page 3: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/3.jpg)
if flowchart
![Page 4: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/4.jpg)
if (sample)
#include <stdio.h>
#include <conio.h>
main()
{
float nilai = 74.01;float nilai = 74.01;
if (nilai >= 65)
{
printf("lulus");
}
getch();
}
![Page 5: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/5.jpg)
if else
if (EXPRESSION)
{
Statement1;
}else{}else{
Statement2;
}
Next_statement;
![Page 6: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/6.jpg)
if else flowchart
![Page 7: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/7.jpg)
if else (sample)
#include <stdio.h>
#include <conio.h>
main()
{
float nilai = 74.01;
if (nilai >= 65)if (nilai >= 65)
{
printf("lulus");
}else{
printf(“tidak lulus");
}
getch();
}
![Page 8: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/8.jpg)
Conditional Operator
• ?
• Condition ? Expression1 : Expression2
• Sample :
X = y > 7 ? 25 : 50X = y > 7 ? 25 : 50
![Page 9: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/9.jpg)
Conditional Operator (cont)
X = y > 7 ? 25 : 50
Equals
if (y > 7)
{
x = 25;
}else{
x = 50;
}
![Page 10: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/10.jpg)
if elseif else
if(EXPRESSION _1)
{
Statement1;
}elseif(EXPRESSION _2){}elseif(EXPRESSION _2){
Statement2;
}else{
Statement3;
}
Next_statement;
![Page 11: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/11.jpg)
if elseif else Flowchart
![Page 12: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/12.jpg)
if else if (sample) #include <stdio.h>
#include <conio.h>
main()
{
float nilai;
printf(“Masukkan nilai : ”);
scanf(“%f”,&nilai);
if (nilai >= 65)if (nilai >= 65)
{
printf(“A");
}else if(nilai == 0){
printf(“Pasti E");
}else{
printf(“Bisa B,C atau D");
}
getch();
}
![Page 13: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/13.jpg)
Nested If
if(expression1)
{
StatementA;
if(expression2)
{
StatementB; StatementB;
}else{
StatementC;
}
}else{
StatementD;
}
Statement E;
![Page 14: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/14.jpg)
Flowchart
![Page 15: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/15.jpg)
Exercise (1)
int a = 1;
int b = 2;
int c;
if(a < b){if(a < b){
c = a + b;
}else{
c = a - b;
}
c ?
![Page 16: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/16.jpg)
Exercise (2)
int a = 1;
int b = 2;
int c;
c = a > b ? a+b : a-bc = a > b ? a+b : a-b
c ?
![Page 17: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/17.jpg)
Exercise (3)int a = 1;
int b = 2;
int c = 1;
int d;
if(a==c){
if(b==c){
d = a + b + c;
}else{
d = a - b + c;
}
}else{
if(a != c){
d = a - b - c;
}else{
d = 0;
}
}
d ?
![Page 18: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/18.jpg)
Exercise (4)
int a = 1;
int b = 2;
int c;
if(a < b){
c = a + b;
}else{
c = a - b;
}
c++;
c ?
![Page 19: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/19.jpg)
Exercise (5)int a = 1;int b = 2;int c = 1;int d;
if(a==c){
if(b==c){
d = a + b + c;
}else{
d = a - b + c;
}
d++;
}else{}else{
if(a != c){
d = a - b - c;
}else{
d = 0;
}
d--;
}
d++;
d ?
![Page 20: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/20.jpg)
switch
switch(number)
{
case 1 :
statement1;
break;
case 2 :
statement2;statement2;
break;
case 3 :
statement3;
break;
default :
statement4;
break;
}
Statement 5;
![Page 21: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/21.jpg)
Flowchart
![Page 22: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/22.jpg)
Sample#include <stdio.h>
#include <conio.h>
main()
{
int pilih;
printf("masukan pilihan [1/0] :"); scanf("%d",&pilih);
switch(pilih)
{
case 1:case 1:
printf("Anda memilih %d",pilih);
break;
case 0:
printf("Anda memilih %d",pilih);
break;
default :
printf(“Input tidak valid“);
break;
}
getch();
}
![Page 23: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/23.jpg)
Exercise (6)
• Buat flowchart dari contoh if else if diatas
• Buat flowchart dari contoh switch diatas
• Buat flowchart dari latihan 1 – 5 diatas
• Buat flowchart proses autentikasi pengisian• Buat flowchart proses autentikasi pengisian
KRS
![Page 24: Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt€¦ · Microsoft PowerPoint - Teori Materi 4 ALGORITMA DAN PEMROGRAMAN II.ppt [Compatibility Mode] Author: User Created Date: 3/27/2008](https://reader034.vdocument.in/reader034/viewer/2022052409/6086f714080a09287d10a5fc/html5/thumbnails/24.jpg)
Question ?Question ?