首页 > 电脑

编写一函数文件y=d_h(num)将十进制正整数转换为十六进制输出。

更新时间2019-09-25 05:19:40

是函数文件,不是脚本文件,跪求答案啊

#define MAXSIZE 30

typedef int ElemType;

/*定义顺序栈结构*#include<stdio.h> /

typedef struct

{ ElemType elem[MAXSIZE];

int top;

}SqStack;/

*初始化栈操作#include<conio.h>*/

void Init(SqStack *s)

{ s->top=-1; }/

*入栈 */

int Push(SqStack *s, ElemType x)

{ if (s->top==MAXSIZE-1) return 0 ; /* 栈满不能入栈 *

else

{ s->top++; s->elem[s->top]=x ; return 1; }

}

/*出栈 */

int Pop(SqStack *s, ElemType *y)

{ if (Empty(s)) return 0; /* 栈空不能出栈 */

else

{ *y=s->elem[s->top]; s->top--; return 1; }/* 栈顶元素存入*y,返回 */

}

/*进制转换*/

void conversion(int N,int R)

{SqStack S

;int x, int i;

Init(&S);

while(N)

{ Push(&S,N%R); /*进栈操作*/

if(i==-1)

{ printf(" 栈已满不能进行入栈操作!");

Return 0;

}

N=N/R;}printf("结果是: ");

while(!Empty(&S)) /*当栈不为空时,出栈操作*/

{ Pop(&S,&x) ;

if(i==-1)

{ printf(" 栈为空不能进行出栈操作!");

return 0;}

else

printf("%x",x);}

/*if*/

}

void main()

{ int Num=1,r;

while(Num>0)

{ clrscr();

printf(" 输入要进行转换的数据(逗号分隔,负数退出) ");

scanf("%d",&Num);

if ((Num>=0)&&(r>0))

conversion(Num,16);

else printf("输入错误!");

getchar(); getchar();

}

}


希望对你有用和帮到你。

你要说明你要使用的语言的,另外,多个语言本身就有进制转换函数的

上一篇:CPU温度过高怎么办

下一篇:=SUM(K2-BZ2)出现#VALUE!怎么才能显示空白