十进制转二进制输出,算法很简单,可以作为入门练习:
#include "pch.h"
#include<iostream>
using namespace std;
int BinaryFunc(int ten) {
int yushu = 0;
int i = 0;
int result = 0;
for (; ten >= 2;) {
yushu = ten % 2;
ten /= 2;
result += (yushu * pow(10,i));
i++;
}
result += (ten* pow(10,i));
return result;
}
void main() {
int ten = 0;
cin >> ten ;
cout << BinaryFunc(ten) << endl;
}