正文

十进制数转任意三十六以内进制数递归算法2009-12-08 08:40:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/shenjinggege/50290.html

分享到:

#include <stdio.h>#include <conio.h>#include <assert.h>#include <string.h>void itob(int n,  int b, char *s){    int sign;    if((sign=n)<0)        n=-n;    if(n/b>0)        itob(n/b,  b, s+1);    else        *(s+1)='\0';    if("%d",n%b<10)        *s=n%b+'0';    else        *s=n%b-10+'A';}int main(){    int n, b;    char s[20];        printf("Recursive convert a decimal number to its counterpart in another number system\n");    printf("Enter n and b, seperate by space:\n");    scanf("%d%d", &n, &b);        assert(b<=36);    itob(n, b, s);    strrev(s);    printf("After convertion, %d=", n);    puts(s);    getch();    return 0;}以上代码是十进制数转任意三十六以内进制数的递归代码输入:897 36输出:Recursive convert a decimal number to its counterpart in another number systemEnter n and b, seperate by space:897 36After convertion, 897=OX

阅读(2363) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册