Q. 99. C++ program to convert a Decimal number to its Binary format.
Copy Code:
#include <iostream>
using namespace std;
int main()
{
int i, n, a[20];
cout << "Enter a Number : ";
cin >> n;
for ( i=0 ; n>0 ; ++i )
{
a[i] = n%2;
n = n/2;
}
cout << "Binary Equivalent is : ";
for ( i = i-1 ; i>=0 ; --i )
cout << a[i];
return 0;
}
No comments:
Post a Comment