zein69

230030258

Nov 17th, 2023
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void decToBinary(int input)
  6. {
  7.     int binaryNum[32];
  8.     int i = 0;
  9.     while (input > 0) {
  10.         binaryNum[i] = input % 8;
  11.         input = input / 8;
  12.         i++;
  13.     };
  14.     cout<<"Hasilnya ";
  15.     for (int j = i - 1; j >= 0; j--){
  16.         cout << binaryNum[j];
  17.     };
  18. }
  19.  
  20. int main()
  21. {
  22.     int input;
  23.     cout<<"Masukan bilangan decimal : ";
  24.     cin>>input;
  25.     if(input < 0){
  26.         cout<<"Masukan Bilangan Decimal Yang Lebih Dari 0";
  27.     }else{
  28.         decToBinary(input);
  29.     }
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment