Advertisement
vencinachev

BinToDecC++

Feb 18th, 2021
843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void binToDec(int number){
  6.     string bin = "";
  7.     while (number != 0){
  8.         bin += (number % 2) + '0';
  9.         number /= 2;
  10.     }
  11.     for (int i = bin.size() - 1; i >= 0; i--){
  12.         cout << bin[i];
  13.     }
  14.     cout << endl;
  15. }
  16.  
  17. int main()
  18. {
  19.     int num;
  20.     cout << "Enter decimal number: ";
  21.     cin >> num;
  22.     cout << "Binary: ";
  23.     binToDec(num);
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement