zoukankan      html  css  js  c++  java
  • 数制转化


    #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 "d:jsmystack.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("
    
    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>
    
    #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;
         }
    

      

  • 相关阅读:
    javascript设计模式(一)职责链模式China of responsibility
    javascript设计模式(一)策略模式Strategy
    angularjs提示消息弹出框
    Javascript设计模式(一)States
    Javascript设计模式(一)Facade
    NOIP2020
    RMQ & ST表
    NOI Linux
    初赛解析
    贪心大解析
  • 原文地址:https://www.cnblogs.com/wc1903036673/p/3395257.html
Copyright © 2011-2022 走看看