Skip to content

Konversi Bilangan Desimal ke Biner dengan C++

January 16, 2011

#include <iostream>
#include <string>
using namespace std;
void binary(int desimal);

int main()
{
int desimal;

cout << “Masukkan bilangan integer positif “;
cin >> desimal;
if (desimal < 0)
cout << “Bukan bilangan desimal\n”;
else {
cout << desimal << ” dikonversi menjadi binary adalah “;
binary(desimal);
cout << endl;
}

return 0;
}
void binary(int desimal)
{ int sisa;
if ( desimal <=1)
{
cout<<desimal;
return;
}
sisa = desimal %2;
binary(desimal>>1);
cout<<sisa;

}

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: