C++编写的十进制转换成16进制代码

2015-06-29 0 691
C++编写的十进制转换成16进制代码
//Decimal to hexadecimal number
//programming by : Erfan Nasoori
//Date of send : 2009/1/11
 
#include <iostream.h>
 
void main()
{
 int x,y,i;
 int d,n=1;
 int * r;
 char h[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
 
 cout<<"Enter x : ";
 cin>>x;
 y=x;
 while(x >= 10)
 {
    x/=10;
   ++n;
 }
 r=new int[n];
 for(i=0 ; y >= 16 ; ++i)
 {
    r[i]=y%16;
   y /= 16;
 }
 r[i++]=y;
 
 cout<<"16 base = ";
 for(i=(n-1) ; i>=0 ; --i)
 {
    cout<<h[r[i]];
 }
cin.get();
}

遇见资源网 c/c++ C++编写的十进制转换成16进制代码 http://www.ox520.com/10198.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务