Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

convert decimal to binary in c++

#include<iostream>
#include<vector>
using namespace std;

void Decimal_To_Binary(int num)
{
	string s;
	vector<int> v;
	int i = 0;
	while (num != 0)
	{
		
		v.push_back(num % 2);
		num /= 2;
		i++;
	}
	reverse(v.begin(), v.end());
	for (auto n : v)
	{
		cout << n;  
	}
	//or
	/*for (int i = 0; i<v.size(); i++)
	{
		cout<< v[i]; 
	}*/
}
int main()
{
	int  num;
	cin >> num;
	Decimal_To_Binary(num);
	
	return 0;
}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #convert #decimal #binary
ADD COMMENT
Topic
Name
3+2 =