#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

评论