zoukankan      html  css  js  c++  java
  • 数制转化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); }







      

  • 相关阅读:
    一个禁止某个document element对象选中文本的js方法
    LNMP中nginx和php的安装流程
    nginx编译
    nginx服务器管理
    nginx+phpfpm配置文件的组织结构
    win 8 x64 english key
    WdatePicker 设置时间范围在某个时间段
    Vm workstation安装win8 的问题
    android 开发中xml的解析
    多线程下载文件
  • 原文地址:https://www.cnblogs.com/wc1903036673/p/3395435.html
Copyright © 2011-2022 走看看