/*
*Copyright (c) 2014
*All rights reserved.
*文件名称:main.cpp
*作 者:臧云吉
*完成日期:2014年11月18日
*版 本 号:v1.0
*
*问题描述:将十进制转化为二进制
*输入描述:输入一个数
*程序输出:输出对应的二进制
*/
#include<iostream>
using namespace std;
void dec2bin(int);
int main()
{
int n;
cout<<"please enter a number:";
cin>>n;
cout<<"the corresponding bimary is:";
dec2bin(n);
cout<<endl;
}
void dec2bin(int n)
{
if(n>0)
{
dec2bin(n/2);
cout<<n%2;
}
}
运行结果