Skip to content

Instantly share code, notes, and snippets.

@lnrsoft
Last active January 4, 2024 21:42
Show Gist options
  • Save lnrsoft/29c9868ce1e0433f5823d317beb89739 to your computer and use it in GitHub Desktop.
Save lnrsoft/29c9868ce1e0433f5823d317beb89739 to your computer and use it in GitHub Desktop.
Decimal to Binary Conversion Algorithm.cpp
#include <iostream>
using namespace std;
int main() {
int a[10], n, i;
cout << "Enter the number to convert: ";
cin >> n;
for (i = 0; n > 0; i++) {
a[i] = n % 2;
n = n / 2;
}
cout << "Binary of the given number= ";
for (i = i - 1; i >= 0; i--) {
cout << a[i];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment