#include <iostream> #include <string> using namespace std; int main() { /*string a; int p = 1; int s = 0; cout<<"请输入一个二进制数:"; cin>>a; for(int i = a.length()-1;i>=0;i--){ int x = a[i]-'0'; s += x*p; p *= 2; } cout<<s<<endl; */ int a[10],n,i; cout<<"请输入一个十进制数:"; cin>>n; for(i=0;n>0;i++){ a[i] = n%2; n = n/2; } for(i=i-1;i>=0;i--){ cout<<a[i]; } return 0; }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/288873.html