就你那道题 随便写了一下 很乱 你看看吧
#include <stdio.h>
#define MAXSIZE 32
typedef struct{
int *elem;
int max;
int top;
}Stack;
int InitStack(Stack *S,int n)
{
S->elem = (int *)malloc(n * sizeof(int));
if (S->elem == NULL)
return -1;
S->max = n;
S->top= 0;
return 0;
}
int Push(Stack *S,int item)
{
if(S->top == S->max)
{
printf("Stack is full!/n");
return -1;
}
S->elem[S->top++]=item;
return 0;
}
int StackEmpty(Stack S)
{
return ((!S.top) ? 1:0);
}
int Pop(Stack*S)
{
if (!S->top)
{
printf("Pop an empty stack!/n");
return -1;
}
return S->elem[--S->top];
}
void MultibaseOutput(long n,int B)
{
int m;
Stack S;
if (InitStack(&S,MAXSIZE))
{
printf("Failure!/n");
return;
}
do
{
if (Push(&S,n%B))
{
printf("Failure!/n");
return;
}
n = n/B;
}while (n != 0);
while (!StackEmpty(S))
{
m = Pop(&S);
if (m < 10)
printf("%d",m);
else
printf("%c",m + 55);
}
}
#include <stdio.h>
long atoi(char s[],int b)
{
int i,n;
n=0;
for(i=0;s[i]>='0'&&s[i]<='9';++i)
n=b*n+(s[i]-'0');
return n;
}
main()
{
long m,b1,b2;
int i=0;
char c;
char *sm,*sb1,*sb2;
printf("A$=");
for(c=getchar();c!='<';c=getchar())
sm[i++]=c;
sm[i]='/0';
for(c=getchar(),i=0;c!='>';c=getchar())
sb1[i++]=c;
sb1[i]='/0';
for(c=getchar(),i=0;c!='/n';c=getchar())
sb2[i++]=c;
sb2[i]='/0';
b1=atoi(sb1,10);
b2=atoi(sb2,10);
m=atoi(sm,b1);
printf("%s<%s>%s=",sm,sb1,sb2);
MultibaseOutput(m,b2);
printf("<%ld>",b2);
getch();
}
懒得写注释了 在wintc下调试通过
对了 我是 多非光 :)