Pengambilan Keputusan dengan Switch


1. Perbedaan if else dan switch case:
– if else Menyeleksi suatu kondisi yang terpenuhi, selanjutnya proses penyeleksian masih dilakukan pada struktur berikutnya.
– Switch Case Bila salah satu kondisi sudah terpenuhi dan blok program sudah diperoses, selanjutnya blok program tidak dilanjutkan.

2. program menampilkan nama – nama bulan menggunakan switch!

Contoh : masukkan bulan = 1

Nama bulan Januari

masukkan bulan = 2

Nama bulan Pebruari

Script:
#include<stdio.h>

main()

{

int x;

printf(“Masukkan Bulan ke-: “);

scanf(“%d”,&x);

switch(x)

{

case 1: printf(“Januari”); break;

case 2: printf(“Februari”); break;

}

}

Output:
Masukkan Bulan ke-: 1

Januari

3. Contoh program switch case:
Script:
#include<stdio.h>

main()

{

int x;

printf(“Masukkan hari ke-: “);

scanf(“%d”,&x);

switch(x)

{

case 1: printf(“Senin”); break;

case 2: printf(“Selasa”); break;

case 3: printf(“Rabu”); break;

case 4: printf(“Kamis”); break;

case 5: printf(“Jum’at”); break;

case 6: printf(“Sabtu”); break;

case 7: printf(“Minggu”); break;

}

}

Output:
Masukkan hari ke-: 1

Senin

4. Script dengan if else:

if ( nama == a || nama == A)

nama = anton;

else if ( nama == b || nama == B)

nama = budi;

else if ( nama == c || nama == C)

nama = chintya;

else

printf(“tidak ada data : %s “, nama);

Script dengan switch case:

switch(nama)

{

case ‘A’: printf(“Anton”); break;

case ‘a’: printf(“Anton”); break;

case ‘B’: printf(“Budi”); break;

case ‘b’: printf(“Budi”); break;

case ‘C’: printf(“Chintya”); break;

case ‘c’: printf(“Chintya”); break;

default: printf(“Tidak ada data:%c”,nama); break;

}

3 Comments Add yours

  1. Elton mengatakan:

    Pilots complete flights for their airline, using their simulator, either online (using a network such as Sim – Miles)
    or offline, and then file a pilot report. It is also a good practice to make sure that none of the climbers are more tired than the other.
    Multiple PC and Controller Support Install on as many PCs/MAC as you
    like. Hardness is less then quartz, or ca 6 on Mohs scale.
    3) Physical parameters: The simulators are almost real, but actually they are
    on the ground, I mean around the sea level.

  2. Hi there to every one, for the reason that I am actually keen of reading this website’s post to be
    updated on a regular basis. It carries pleasant data.

  3. Mariakonline.Net mengatakan:

    Since the admin of this website is working, no uncertainty very soon it
    will be renowned, due to its feature contents.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s