欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

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

十进制转十六进制

[复制链接]
script 发表于 2011-11-25 00:11 | 显示全部楼层 |阅读模式
#include<iostream>
#include<cstdlib>
#include<stdio.h>
using namespace std;

int main()
{
                int n;
                cout<<"请输入:";
                cin>>n;
                char a[8];
                int i=0;
                int m=0;
                while(n>0)
                {
                        m=n%16;
                        if(m<10)
                                a[i]=m+48;
                        else if(m==10)
                                a[i]='A';
                        else if(m==11)
                                a[i]='B';
                        else if(m==12)
                                a[i]='C';
                        else if(m==13)
                                a[i]='D';
                        else if(m==14)
                                a[i]='E';
                        else if(m==15)
                                a[i]='F';
                        n=n/16;
                        i++;
                }
                cout<<endl;
                cout<<"0x";
                for(int k=i-1;k>=0;k--)
                        cout<<a[k];
                cout<<endl;
                system("pause");
}

相关帖子

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

GMT+8, 2024-4-25 17:09 , Processed in 0.043528 second(s), 9 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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