Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions C++/Program 29/DecimaltoBinary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// number to binary number

#include <iostream>
using namespace std;

// function to convert decimal to binary
void decToBinary(int n)
{
// array to store binary number
int binaryNum[32];

// counter for binary array
int i = 0;
while (n > 0) {

// storing remainder in binary array
binaryNum[i] = n % 2;
n = n / 2;
i++;
}

// printing binary array in reverse order
for (int j = i - 1; j >= 0; j--)
cout << binaryNum[j];
}

// Driver program to test above function
int main()
{
int n = 17;
decToBinary(n);
return 0;
}
1 change: 1 addition & 0 deletions C++/Program 29/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C++ program to convert a decimal.