繁体   English   中英

十进制到十六进制的问题 function 不返回任何内容

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM