44 lines
582 B
C
44 lines
582 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
char ans[20];
|
|
|
|
int i ;
|
|
|
|
void convert(int n, int b);
|
|
|
|
void convert(int n, int b){
|
|
if(n==0) return;
|
|
convert( n / b , b);
|
|
|
|
if(n % b <10){
|
|
printf("%c",n % b + '0');
|
|
}else {
|
|
printf("%c",(n % b)-10 + 'A');
|
|
}
|
|
|
|
}
|
|
|
|
int main(){
|
|
int n , b ,count ;
|
|
while(1){
|
|
i = 0;
|
|
printf("\n輸入待轉換的十進位正整數 ==> ");
|
|
scanf("%d",&n);
|
|
|
|
if(n<=-1) break;
|
|
|
|
printf("\n輸入轉換之基底 ==> ");
|
|
scanf("%d",&b);
|
|
printf("(%d)_10 = (",n);
|
|
|
|
convert(n,b);
|
|
|
|
printf(")_%d\n",b);
|
|
}
|
|
printf("\n程式將結束...");
|
|
system("pause");
|
|
|
|
return 0;
|
|
}
|