You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
933 B
61 lines
933 B
#include<stdlib.h>
|
|
#import <MobileCoreServices/MobileCoreServices.h>
|
|
|
|
#define maxsize 100
|
|
typedef struct
|
|
{
|
|
int *base;
|
|
int *top;
|
|
int stacksize;
|
|
} sqstack;
|
|
|
|
void initstack(sqstack &s)
|
|
{
|
|
s.base = malloc(maxsize*sizeof(int));
|
|
if(!s.base)exit;
|
|
s.top=s.base;
|
|
s.stacksize=maxsize;
|
|
}
|
|
|
|
void push(sqstack &s,int e){
|
|
if(s.top-s.base==s.stacksize)return;
|
|
*s.top++=e;
|
|
return;
|
|
}
|
|
|
|
void pop(sqstack &s,int &e){
|
|
if(s.top==s.base)return;
|
|
e=*--s.top;
|
|
return;
|
|
}
|
|
|
|
void zhuanhuan(sqstack &a,int e){
|
|
int temp;
|
|
while(e!=0){
|
|
temp=e%16;
|
|
push(a,temp)
|
|
e=e/16;
|
|
}
|
|
string str;
|
|
while(s.top==s.base){
|
|
int n=0;
|
|
pop(a,n)
|
|
if(n>=10){
|
|
str = char('A'-10+n)+str;
|
|
}
|
|
else{
|
|
str=char('0'+n)+str
|
|
}
|
|
}
|
|
cout << "转化后的十六进制数如下" << endl;
|
|
}
|
|
|
|
int main(){
|
|
int a=0;
|
|
sqstack* y=(sqstack*)malloc(sizeof(sqstack));
|
|
initstack(y);
|
|
cout << "请输入想要转化的十进制数字" << endl;
|
|
cin >> a;
|
|
zhuanhuan(y,a)
|
|
}
|
|
} |