Advertisement
xathrya

Decimal to Binary

Dec 11th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void dec2bin(int d, int limit)
  5. {
  6.     if (d != 0) {
  7.         if (limit == 4) {
  8.             dec2bin(d / 2, 0);
  9.             cout << (d%2);
  10.             cout << ' ';
  11.         } else {
  12.             dec2bin(d / 2, limit+1);
  13.             cout << (d%2);
  14.         }
  15.     }
  16. }
  17.  
  18. int main() {
  19.     int d;
  20.     cout << "Masukkan angka: "; cin >> d;
  21.     cout << "Hasilnya: ";   dec2bin(d, 0);
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement