数制转化
#include <stdlib.h> #include <stdio.h> #include "G:\JS\mystack.h" int main() { sqstack s; int m,n,r,rod,e; initstack(s); scanf("%d %d",&n,&r); m=n; while (n) { rod=n%r; push(s,rod); n=n/r; } printf("\n\nThe resule is:%d(%d)=",m,r); while (!emptystack(s)) { pop(s,e); if (e>=10) printf("%c",'A'+e-10); else printf("%d",e); } printf("%\n"); }
***********************************
#include <stdlib.h>
#include <stdio.h>
#include "d:\js\mystack.h"
void main()
{
sqstack s;
int m,n,r,rod,e;
initstack(s);
scanf("%d %d",&n,&r);
m=n;
while (n)
{
rod=n%r;
push(s,rod);
n=n/r;
}
printf("\n\nThe resule is:%d(%d)=",m,r);
while (!emptystack(s))
{
pop(s,e);
if (e>=10)
printf("%c",'A'+e-10);
else
printf("%d",e);
}
printf("%\n");
}
*******************************************
#include <stdlib.h>
#include <stdio.h>
#define stackinitsize 20
#define stackincrement 8
typedef struct{
int *base;
int *top;
int stacksize;
}sqstack;
int initstack(sqstack &s)
{s.base=(int * ) malloc(stackinitsize*sizeof(int));
s.top=s.base;
s.stacksize=stackinitsize;
return 1;
}
int push(sqstack &s,int e)
{
*(s.top)=e;
s.top++;
return 1;
}
int gettop(sqstack s)
{
return *(s.top-1);
}
int emptystack(sqstack s)
{if (s.top==s.base) return 1;
else return 0;
}
int pop(sqstack &s,int &e)
{ if (emptystack(s)) return 0;
--s.top;
e=*(s.top);
return 1;
}
浙公网安备 33010602011771号