#include using namespace std;

void decimalToBinary(int n) { if (n == 0) { cout << 0 << endl; return; } int binary[32] = {0}; // 存储二进制数 int i = 0; while (n > 0) { binary[i++] = n % 2; n /= 2; } for (int j = i - 1; j >= 0; j--) { cout << binary[j]; } cout << endl; }

int main() { int n; cin >> n; decimalToBinary(n); return 0; }

用C++写:给定一个不超过 1000 000 000 的正整数 n十进制将其转换成二进制数输出。

原文地址: https://www.cveoy.top/t/topic/b8YO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录