作者whxu (ㄧㄟㄛ夫~好淫穢)
看板NTUEE107HW
標題進位轉換
時間Mon Oct 6 13:48:32 2003
我一位資工同學的計程作業 , 說是規定不能用到 array....
我想到可以用 recursive 做做看 , 不過他說他們也還沒教到 function....||
隨便.....程式執行出來就是輸入一個數再輸入要轉回成的進位 , 輸出結果 !
#include <stdio.h>
void process(int,int);
int main(void)
{
int inNum,outType;
while(1) {
printf("Please input the number to process (-1 to exit) : ");
scanf("%d",&inNum);
if(inNum == -1) break;
printf("Input the output type (2/8/10/16) : ");
scanf("%d",&outType);
process(inNum,outType);
printf("\n");
}
return 0;
}
void process(int inNum,int outType)
{
int temp;
if(inNum >= outType) process(inNum/outType,outType);
temp = inNum % outType;
if(temp > 9) printf("%c",temp+55);
else printf("%d",temp);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.18.101
→ timrau:只有轉二進位要處理,其他都不用處理啊 推 140.112.18.109 10/06
→ timrau:看錯題目了,以為只有2/8/10/16進位 推 140.112.18.109 10/06