数制转化2

#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;
     }

  


#include <stdlib.h>
#include <stdio.h>
#include "G:JSmystack.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("

The 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("%
");
}

  





*********************************************************************************************************




#include <stdlib.h> #include <stdio.h> #include <G:JSmystack.h> int main() { sqstack s; int n,r,mod,e; initstack(s); scanf("%d %d",&n,&r); printf("%d=",n); while (n!=0) { mod=n%r; push(s,mod); n=n/r; } while (!emptystack(s)) { pop(s,e); if (e>=10) printf("%c",'A'+e-10); else printf("%d",e); } printf("(%d) ",r); }







  

原文地址:https://www.cnblogs.com/wc1903036673/p/3395435.html