二进制输出整数

来源:互联网 发布:matlab 关联矩阵 编辑:程序博客网 时间:2024/06/08 03:07
//二进制输出整数;
#include<iostream>void binary_out(int x);using namespace std;int main(){ cout<<"please enter the number: "; int n; cin>>n; cout<<" the binary of "<<n<<" is "; binary_out(n); cout<<endl; return 0;}
void binary_out(int x) //递归实现 输出二进制;{   int a;   a=x%2;   x=x>>1;  if(x==0)   ;  else   binary_out(x);   cout<<a;}
0 0
原创粉丝点击