無聊寫的,算法寫的很糟,歡迎批評指正
#include <iostream>
#include <cmath>
using namespace std;
void Dec_Bin(int);
int main()
{
int num;
cout << "Please input a DEC number:";
cin >> num;
Dec_Bin(num);
cout << endl;
system("pause");
return 0;
}
void Dec_Bin(int num)
{
int temp[255], i = 0;
while(num > 0)
{
temp[i] = num % 2;
num = floor(num / 2);
i++;
}
cout << "Bin is:";
while(i > 0)
{
cout << temp[i-1];
i--;
}
cout << endl;
}