#include <conio.h> #include <iostream.h> class Biner{ friend istream& operator>>(istream&, Biner&); friend ostream& operator<<(ostream&, Biner&); public: Biner(); void masukan(); void proses(); void keluar(); private: int data[100],l,a; }; Biner::Biner(){ cout<<"program mengkonversi bilangan desimal ke biner"<<endl; } istream& operator>>(istream& in, Biner& masukan){ cout<<"masukan angka:"; in>>masukan.a; } void Biner::proses(){ int i; i=0;l=0; while(a!=1){ data[i]=a%2; a=a/2;i=i+1;l=l+1; } } void Biner::keluar(){ cout<<"hasil biner adalah :"<<1; for(int i=l-1;i>=0;i--){ cout<<data[i];} } int main(){ Biner x; cin>>x; x.proses(); x.keluar(); getch(); }
Monday, April 16, 2012
Konversi Dari Desimal Ke Biner
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment