Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Alg-dec-bin.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include <vector>
- using namespace std;
- vector <int> decimalToBinary(int num)
- {
- vector <int> vResult = {};
- while (num)
- {
- vResult.push_back (num % 2);
- num /= 2;
- }
- return vResult;
- }
- int main()
- {
- int num;
- cin >> num;
- vector <int> vBinary = decimalToBinary(num);
- for (int i = vBinary.size() - 1; i >= 0; i--)
- {
- cout << vBinary[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment