English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

各位大大~老師丟一個問題給我們!!!
我寫出來就是執行怪怪的....
請各位大大幫我看看我的程式!!


請設計一個名為toBaseN的函式,要求使用者輸入2個名為intput與base的整數,並將input的內容以base進制方式輸出至螢幕。


#include
void toBaseN(int n);
int main(int argc, char *argv[])
{
int n;
int b;
printf("請輸入一個正整數:");
scanf("%d",&n);
printf("請輸入將轉換的進制:");
scanf("%d",&b);
printf("toBase(%d)=",n);
toBaseN(n);
printf("\n");
system("pause");
return 0;
}
void toBaseN(int n)
{
int b;
if(n/b==0){
printf("%d",n%b);
}else{
toBaseN(n/b);
printf("%d",n%b);
}
}

2007-12-01 07:28:51 · 3 個解答 · 發問者 致賢-95-SDr-01 1 in 電腦與網際網路 程式設計

3 個解答

#include
#include
#include
int main(int argc, char* argv[]){
//=====START=====//
int n,b;
char buffer[32767];
printf("Input Number: "),scanf("%d",&n);
printf("Input Base: "),scanf("%d",&b);
printf("Output= %s\n",itoa(n,buffer,b));
//=====END=====//
system("PAUSE");
return 0;
}

2007-12-01 07:45:41 · answer #1 · answered by Big_John-tw 7 · 0 0

#include
void toBaseN(int n,int i);
int main(int argc, char *argv[])
{
int n;
int b;
printf("請輸入一個正整數:");
scanf("%d",&n);
printf("請輸入將轉換的進制:");
scanf("%d",&b);
printf("toBase(%d)=",n);
toBaseN(n,b);
printf("\n");
return 0;
}
void toBaseN(int n,int i)
{
int *b=new int[],c;
char num[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','N','M','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
for(c=0;n>0;n/=i,c++)
*(b+c)=n%i;
while(--c>=0)
printf("%c",num[*(b+c)]);
}

2007-12-01 15:23:05 補充:
抱歉我重寫一下 toBaseN的內容
void toBaseN(int n,int i)
{
int c;
char num[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','N','M','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
if(n/i>0)//這個大於符號要改半形
toBaseN(n/i,i);
printf("%c",num[n%i]);
}

2007-12-01 16:24:14 補充:
抱歉我才大一只會寫
不會計算堆疊空間什麼的
可以說清楚一點嗎?

2007-12-01 10:05:48 · answer #2 · answered by 達達 5 · 0 0

小綿羊.....
可以跟我講一下....用itoa是什麼的函式ㄇ??
因為我是想用toBaseN的方式寫....

2007-12-01 08:20:53 · answer #3 · answered by 致賢-95-SDr-01 1 · 0 0

fedest.com, questions and answers