欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

玩欧卡就用莱仕达V10方向盘欧卡2入门方向盘选莱仕达V9莱仕达折叠便携游戏方向盘支架欢迎地图Mod入驻
查看: 5796|回复: 0
收起左侧

十进制数转二进制

[复制链接]
script 发表于 2011-11-26 19:46 来自手机 | 显示全部楼层 |阅读模式
做数字设计作业想偷懒可以用一下~
#include<iostream>
#include<cstdlib>
#include<stdio.h>
using namespace std;

int main()
{
                int n;
                cout<<"请输入:";
                cin>>n;
                int a[8];
                for(int j=0;j<8;j++)
                        a[j]=0;
                if(n<0)
                {
                        a[7]=1;
                        n=-n;
                }
                int i=0;
                while(n>0)
                {
                        a[i++]=n%2;
                        n=n/2;
                }
                cout<<endl;
                for(int k=7;k>3;k--)
                        cout<<a[k];
                cout<<" ";
                for(int k=3;k>=0;k--)
                        cout<<a[k];
                cout<<endl;
                system("pause");
}

联系我们|手机版|欧卡2中国 ( 湘ICP备11020288号-1 )

GMT+8, 2024-4-19 18:07 , Processed in 0.036425 second(s), 8 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表