From c32e6e199a9b387a258f48d97de15f1d54f9af6d Mon Sep 17 00:00:00 2001 From: Akash Sharma Date: Sat, 16 Oct 2021 21:31:22 +0530 Subject: [PATCH 1/2] Added a cpp program --- C++/Program 29/DecimaltoBinary.cpp | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 C++/Program 29/DecimaltoBinary.cpp 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 From 9f775b86f433524e3751568edb69785788b82584 Mon Sep 17 00:00:00 2001 From: Akash Sharma Date: Sat, 16 Oct 2021 21:35:52 +0530 Subject: [PATCH 2/2] added readme.md --- C++/Program 29/Readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 C++/Program 29/Readme.md 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