📄 进制转换.cpp
字号:
// 进制转换.cpp : Defines the entry point for the console application.
//
#include "stdio.h"
#include "stdlib.h"
#include "iomanip.h"
#include "seqstack.h"
/*#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef int SElemType;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
void InitStack (SqStack &S)
{
S.base=new SqStack;
if(!S.base)
{
printf("OVERFLOW");
exit(1);
}
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
//return ok;
}
*/
void main()
{
seqstack S;
int n,x,e;
do
{
printf("请输入您想要转换的进制:");
scanf("%d",&x);
if (x>16||x<2)
printf("进制数超范围! \n");
}while(x<2||x>16);
InitStack(S);
printf("请输入您想要转换的数:");
scanf("%d",&n);
printf("十进制数 %d 转换成 %d 进制数为:",n,x);
while (n)
{
Push(S,n%x);
n=n/x;
}
n=0;
while(!Empty(S))
{
e=Pop(S);
if(e<10)
{printf("%d",e);n++;}
else
{printf("%c",e+55);n++;}
if(n>2)
{n=0;printf(" ");}
}
//printf("Hello World!\n");
//return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -