Analisis:
Kasus
biner 4 digit:
Switch(biner){
Case
1000
Case
1001
Case
1010
Case
1011
Case
1100
Case
1101
Case
1110
Case
1111
Algoritma:
{membaca
nilai biner (biner), mencari nilai desimal dengan menggunakan switch)
Deklarasi:
Biner
(integer).
Deskripsi:
Baca
(biner).
Switch
(biner).
Write
(case 1000, case 1001, case 1010, case 1011, case 1100, case 1101, case 1110,
case 1111).
#include <iostream>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int biner;
cout<<"\t\tKonversi Bilangan Biner 4 Digit ke Desimal"<<endl<<endl;
cout<<"Masukkan bilangan biner = "; cin>>biner;
switch(biner){
case 1000:
cout<<"desimal = 8";
break;
case 1001:
cout<<"desimal= 9";
break;
case 1010:
cout<<"desimal = 10";
break;
case 1011:
cout<<"desimal = 11";
break;
case 1100:
cout<<"desimal = 12";
break;
case 1101:
cout<<"desimal = 13";
break;
case 1110:
cout<<"desimal = 14";
case 1111:
cout<<"desimal = 15";
default:
cout<<"selain bilangan biner tidak bisa";
break;
}
return 0;
}
Tidak ada komentar:
Posting Komentar