Hanya sekedar sharing pengetahuan kalau ada salah kata benahi sendiri. Silahkan cek koleksi kaos polos di www.facebooj.com/DunaiPolos

Monday, 5 May 2014

Program Konversi Bilangan

hai guys, kali ini aku mau ngasih sesuatu yang aku dapat
yaitu program konversi bilangan menggunakan bahasa C++
langsung aja sedoottt

#include <iostream.h>
#include <conio.h>

#define namespace std;

int main()
{
int d;
int i=0,n,j,b[100];
char karakter,kembali;

awal:
//clrscr ();
system ("color 2f");
cout<< ":::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;   // ini di adopsi dari modul 1 pada program pertama berguna untuk menampilkan nama,kode, dan lain2
cout<< "::::::::::     PROGRAM INI DISUSUN OLEH       :::::::::: \n" ;
cout<< "::::::::::            WAHYU PRASTYO           :::::::::: \n" ;
cout<< "::::::::::           TINO WICAKSONO           :::::::::: \n" ;
cout<< "::::::::::                                    :::::::::: \n" ;
cout<< "::::::::::                                    :::::::::: \n" ;
cout<< "::::::::::                                    :::::::::: \n" ;
cout<< ":::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;

cout<< "++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n" ;
cout<< "++++             PROGRAM SERBAGUNA                ++++++ \n" ;
cout<< "++++ 1. KONVERSI BILANGAN DESIMAL KE BINER        ++++++ \n" ;
cout<< "++++ 2. KONVERSI BILANGAN DESIMAL KEOCTAL         ++++++ \n" ;
cout<< "++++ 3. KONVERSI BILANGAN DESIMAL KEHEKSADESIMAL  ++++++ \n" ;
cout<< "++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n" ;
cout<< "++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n" ;
cout<< "++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n" ;
cout<<"\nsilahkan pilih menu: ";
cin>>d;

switch(d)
{
case 1:

cout<<"\nmasukan angka desimal: ";
cin>>n;
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;

while(n>0)
{
b[i]=n%2;
n=n/2;
i++;

}

cout<<"\ndalam biner: ";
j=i-1;

for (i=j;j>=0;j--)
{
cout<<b[j];

}
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
cout<<"\napakah anda mau mengulangi? (y/t): ";
cin>>kembali;
if (kembali=='y')
return main ();
else if (kembali=='t')
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
cout<<"terimakasih kami ucapkan";
break;

case 2:
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
cout<<"\nmasukkan bilangan desimal: ";
cin>>n;
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;

while (n>0)
{
b[i]=n%8;
n=n/8;
i++;
}
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
cout<<"\n masukkan bilangan oktal :";
j=i-1;

for (i=j;j>=0;j--)
{
cout<<b[j];
}
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
cout<<"\napakah anda mau mengulangi? (y/t): ";
cin>>kembali;
if (kembali=='y')
return main ();
else if (kembali=='t')
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
cout<<"terimakasih kami ucapkan";
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
break;

case 3:
cout<<"\n\t\tmasukan angka desimal: ";
cin>>n;
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
while (n>0)
{
b[i]=n%16;
n=n/16;
i++;
}

cout<<"\n\t\tdalam hexa:";
j=i-1;
for (i=j;j>=0;j--)
{
if(b[j]<10)
{
cout<<b[j];
}
else
{
switch(b[j])
{
case 10:
cout<<"A";
break;
case 11:
cout<<"B";
break;
case 12:
cout<<"C";
break;
case 13:
cout<<"D";
break;
case 14:
cout<<"E";
break;
case 15:
cout<<"F";
break;
default :
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
cout<<"maaf pilihan anda salah\n";
return main ();
}
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
cout<<"\napakah anda mau mengulangi? (y/t): ";
cin>>kembali;
if (kembali=='y')
return main ();
else if (kembali=='t')
cout<< "\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n" ;
cout<<"terimakasih kami ucapkan";
}
getche ();
}
}
}