数值转换问题(顺序栈)

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

typedef int DataType;

#define MAXSIZE 100

typedef struct 

{

    DataType data[MAXSIZE];

    int top;        

}seqstack;//顺序栈

int main()

{

     int N,r;

     DataType x;

     scanf("%d%d",&N,&r);

     seqstack *s;

     s=(seqstack *)malloc(sizeof(seqstack));

     s->top=-1;

     while(N)

     {

         if(s->top!=MAXSIZE-1)

         {

              s->top++;

              s->data[s->top]=N%r;//入栈

              N=N/r;

         }

     }

     while(s->top!=-1)

     {

          x=s->data[s->top];

          printf(" %d",x);

          s->top--;//出栈

     }

     printf("\n");

     system("pause");

     return 0;

}

你可能感兴趣的:(转换)