Upload
others
View
24
Download
0
Embed Size (px)
Citation preview
Penyeleksian Kondisi
• if
• if else
• if else if
• switch
if
if (EXPRESSION)
Statement;
Next_statement;
OROR
if (EXPRESSION)
{
Statement;
}
Next_statement;
if flowchart
if (sample)
#include <stdio.h>
#include <conio.h>
main()
{
float nilai = 74.01;float nilai = 74.01;
if (nilai >= 65)
{
printf("lulus");
}
getch();
}
if else
if (EXPRESSION)
{
Statement1;
}else{}else{
Statement2;
}
Next_statement;
if else flowchart
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();
}
Conditional Operator
• ?
• Condition ? Expression1 : Expression2
• Sample :
X = y > 7 ? 25 : 50X = y > 7 ? 25 : 50
Conditional Operator (cont)
X = y > 7 ? 25 : 50
Equals
if (y > 7)
{
x = 25;
}else{
x = 50;
}
if elseif else
if(EXPRESSION _1)
{
Statement1;
}elseif(EXPRESSION _2){}elseif(EXPRESSION _2){
Statement2;
}else{
Statement3;
}
Next_statement;
if elseif else Flowchart
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();
}
Nested If
if(expression1)
{
StatementA;
if(expression2)
{
StatementB; StatementB;
}else{
StatementC;
}
}else{
StatementD;
}
Statement E;
Flowchart
Exercise (1)
int a = 1;
int b = 2;
int c;
if(a < b){if(a < b){
c = a + b;
}else{
c = a - b;
}
c ?
Exercise (2)
int a = 1;
int b = 2;
int c;
c = a > b ? a+b : a-bc = a > b ? a+b : a-b
c ?
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 ?
Exercise (4)
int a = 1;
int b = 2;
int c;
if(a < b){
c = a + b;
}else{
c = a - b;
}
c++;
c ?
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 ?
switch
switch(number)
{
case 1 :
statement1;
break;
case 2 :
statement2;statement2;
break;
case 3 :
statement3;
break;
default :
statement4;
break;
}
Statement 5;
Flowchart
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();
}
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
Question ?Question ?