/*
* Copyright (c) 2014,烟台大学计算机学院
* All rights reserved.
*文件名称: test.cop
*作者:翟兴雷
*完成日期:2014年11月13日
*版本号:v1.0
*
*问题描述:把整数换成二进制
*输入描述:
*程序输出:
*/
#include <iostream>
using namespace std;
void dec2bin(int);
int main()
{
int n;
cout<<"请输入一个整数:";
cin>>n;
cout<<n<<"对应的二进制形式为:";
dec2bin(n); //输出n对应的二进制串
cout<<endl;
return 0;
}
void dec2bin(int n)
{if(n==0)
return;
else{
dec2bin(n/2);
cout<<n%2;
return;
}
}