diff --git a/C++/Program 29/DecimaltoBinary.cpp b/C++/Program 29/DecimaltoBinary.cpp new file mode 100644 index 00000000..be854a50 --- /dev/null +++ b/C++/Program 29/DecimaltoBinary.cpp @@ -0,0 +1,33 @@ +// number to binary number + +#include +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; +} \ No newline at end of file diff --git a/C++/Program 29/Readme.md b/C++/Program 29/Readme.md new file mode 100644 index 00000000..13485264 --- /dev/null +++ b/C++/Program 29/Readme.md @@ -0,0 +1 @@ +C++ program to convert a decimal. \ No newline at end of file