1.cpp

来自「数据结构中如何将十进制转换为六禁止」· C++ 代码 · 共 57 行

CPP
57
字号
typedef int SElemType;
typedef int QElemType;

#include "commdef.h"
#include "sqstack.h"
#include "SqQueue传引用.h"
#include"math.h"

void zhengshu(int N)
{int a;
SqStack S;
SElemType e;
 InitStack(S); 
 if(N==0)  Push(S,0);
 while(N!=0)
 { a=N%16;
  
   Push(S,a);
  
      N=N/16;
  }
 while(!StackEmpty(S))
 {
  Pop(S,e);
  printf("%X",e);
  
 }
}

void xiaoshu(float m)
{int a;int bit=0;
SqQueue Q;
QElemType e;
InitQueue(Q);
     while(fabs(m)>1e-6&&bit<5)
       {m=m*16;
         a=(int)m;
       
         EnQueue(Q,a); 
         m=m-a;
		 bit++;
        }
   while(Q.rear!=Q.front)
   {
    DeQueue(Q,e);
      printf("%X",e);
    }
}
void main()
{float c,m;int N;
scanf("%f",&c);
N=(int) c;
 m=c-N;
zhengshu(N);
 if (m!=0) printf(".");
 xiaoshu(m);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?