#include <iostream> #include <Windows.h> using namespace std; int main(void) { int n = 0; int ret[32]; int i = 0; cout << "请输入一个正整数:"; cin >> n; while (n != 0) { ret[i] = n % 2; n = n / 2; i++; } for (i--; i >= 0; i--) { cout << ret[i]; } cout << endl; system("pause"); return 0; }
原文:https://www.cnblogs.com/tanghaiyong/p/11437622.html