Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void dec2bin(int d, int limit)
- {
- if (d != 0) {
- if (limit == 4) {
- dec2bin(d / 2, 0);
- cout << (d%2);
- cout << ' ';
- } else {
- dec2bin(d / 2, limit+1);
- cout << (d%2);
- }
- }
- }
- int main() {
- int d;
- cout << "Masukkan angka: "; cin >> d;
- cout << "Hasilnya: "; dec2bin(d, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement