现在的位置: 首页 > 综合 > 正文

2012.1

2014年02月20日 ⁄ 综合 ⁄ 共 236字 ⁄ 字号 评论关闭

#include<iostream>
using namespace std;
void d2b(int n)
{
 if(n==1)
 {
  cout<<1;
 }
 else
 {
  cout<<n%2;
  d2b(n/2);
 }
}
int main()
{
 int a;
 cout<<"请输入十进制数:"<<endl;
 cin>>a;      //输入十进制数
 cout<<"输出二进制数:"<<endl;
 d2b(a);      //转换成二进制数输出
 cout<<endl;
 return 0;
}

抱歉!评论已关闭.