zoukankan      html  css  js  c++  java
  • 十进制转换2-9进制转换

    #include <stdio.h>
    void to_base_n(int x, int base);
    int main(void)
    {
        int number;
        int b;
        int count;
        printf("Enter an integer (q to quit):
    ");
        while (scanf("%d", &number) == 1)
            {
                printf("Enter number base (2-9): ");
                while ((count = scanf("%d", &b))== 1&& (b < 2 || b > 10))
                {
                        printf("base should be in the range 2-10: ");
                }
                if (count != 1)
                    break;
                printf("Base %d equivalent: ", b);
                to_base_n(number, b);
                putchar('
    ');
                printf("Enter an integer (q to quit):
    ");
            }
                printf("Done.
    ");
                return 0;
    }
    void to_base_n(int x, int base) /* recursive function */
    {
        int r;
        r = x % base;
        if (x >= base)
            to_base_n(x / base, base);
        putchar('0' + r);
    }

  • 相关阅读:
    VBA键码常数
    枚举
    海龟交易法则及头寸
    HQL.TOP
    jquery.cookie
    机械操作产品分析.
    Repeater排序2
    Repeater排序
    json
    LoginStatus注销控件
  • 原文地址:https://www.cnblogs.com/WALLACE-S-BOOK/p/9732323.html
Copyright © 2011-2022 走看看