You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
#include<iostream>
|
|
using namespace std;
|
|
|
|
//功能:将一个十进制数转化为二进制数
|
|
void bin2(int n) {
|
|
int i,j=0;
|
|
int a[1000];
|
|
i=n;
|
|
if(i==0) {
|
|
cout<<"0"<<endl;
|
|
}
|
|
while(i) {
|
|
a[j]=i%2;
|
|
i/=2;
|
|
j++;
|
|
}
|
|
for(i=j-1; i>=0; i--)
|
|
cout<<a[i];
|
|
cout<<endl;
|
|
}
|
|
|
|
int main() {
|
|
bin2(12);
|
|
return 0;
|
|
}
|