![](/img/trans.png)
[英]return the minimum of three int's in function doesn't return anything
[英]Trouble with a decimal to hexadecimal function that doesn't return anything
當我編譯這個時,沒有任何返回,它只是我可以輸入的空白空間,但是沒有任何反應而不是計算程序,有什么原因嗎?
#include <stdio.h>
void decimalToHex(long int decValue);
int main()
{
long int decValue = 20;
decimalToHex(decValue);
return 0;
}
void decimalToHex(long int decValue)
{
long int remainder,quotient;
int i=1,j,temp;
char hexadecimalNumber[100];
quotient = decValue;
while(quotient!=0)
{
temp = quotient % 16;
if( temp < 10)
temp =temp + 48;
else
{
temp = temp + 55;
hexadecimalNumber[i++]= temp;
quotient = quotient / 16;
}
}
printf("Equivalent hexadecimal value of decimal number %ld: ",decValue);
for(j = i -1 ; j> 0; j--)
printf("%c",hexadecimalNumber[j]);
printf("\nGoodbye!\n");
}
hexadecimalNumber[i++]= temp;
quotient = quotient / 16;
嗯,這不應該在 else 之外嗎? 是的,它應該。
while(quotient!=0)
當我們這樣做時,這應該是一個 do/while 循環而不是 while 循環。 總是 go 循環一次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.