完全正确的十进制转换其他任何进制,朋友帮我改的
2006-05-07 13:50
253 查看
#include"stdio.h"
#define maxsize 100
typedef struct stack
{
int a[maxsize];
int top;
}stack;
void init_stack(stack &sq)
{sq.top=0;}
int stackempty(stack sq)
{
return(sq.top?0:1);
}
void push(stack &sq,int x)
{
if(sq.top==maxsize)
printf("the stack is full");
sq.a[sq.top++]=x;
}
int pop(stack &sq)
{
if(stackempty(sq))
{
printf("the stack is empty");
}
sq.top--;
return sq.a[sq.top];
}
void jinzhizhuanhuan(int N,int B)
{
int i;
stack sq;
init_stack(sq);
while(N)
{
push(sq,N%B);
N=N/B;
}
while(!stackempty(sq))
{
i=pop(sq);
printf("%d",i);
}
}
main()
{
int N,B;
printf("输入一个十进制数:");
scanf("%d",&N);
printf("转换为几进制 :");
scanf("%d",&B);
jinzhizhuanhuan(N,B);
printf("/n");
}
#define maxsize 100
typedef struct stack
{
int a[maxsize];
int top;
}stack;
void init_stack(stack &sq)
{sq.top=0;}
int stackempty(stack sq)
{
return(sq.top?0:1);
}
void push(stack &sq,int x)
{
if(sq.top==maxsize)
printf("the stack is full");
sq.a[sq.top++]=x;
}
int pop(stack &sq)
{
if(stackempty(sq))
{
printf("the stack is empty");
}
sq.top--;
return sq.a[sq.top];
}
void jinzhizhuanhuan(int N,int B)
{
int i;
stack sq;
init_stack(sq);
while(N)
{
push(sq,N%B);
N=N/B;
}
while(!stackempty(sq))
{
i=pop(sq);
printf("%d",i);
}
}
main()
{
int N,B;
printf("输入一个十进制数:");
scanf("%d",&N);
printf("转换为几进制 :");
scanf("%d",&B);
jinzhizhuanhuan(N,B);
printf("/n");
}
相关文章推荐
- 用数组实现十进制与其他进制的转换
- 十进制转换为其他进制数
- 十进制与其他进制之间的转换
- python编程实现十进制的转换(十进制到任何进制不用系统函数实现)
- C语言:其他进制转换为十进制(方法二)
- java 使用查表法将十进制转换成十六进制其他进制
- 数据结构的应用——使用栈实现十进制到其他(2、8、16)进制的转换
- P122 第三章 20题 十进制转换其他进制
- 【C#食谱】【风味小吃】菜单7:把其他进制的数转换为十进制
- 使用“栈”完成十进制到其他进制的转换
- 栈的应用1——十进制转换任何进制
- 数据结构的应用——使用栈实现十进制到其他(2、8、16)进制的转换
- Java转换十进制为其他进制的两种方法
- 制表法将十进制转换为其他进制
- 递归实现十进制到2(其他)进制的转换
- 数据结构示例之十进制转换其他进制
- 将十进制的数转换为任何进制的数
- 十进制的数转换成其他进制的数
- 十进制转换为任何进制
- 二进制、十进制、其他进制之间的转换