不返回数组值

时间:2019-02-11 00:01:22

标签: c

// function to convert decimal to binary 
int *decToBinary(int n) 
{ 
    // array to store binary number 
    static int *binNum; //, array_bin[31]; 

    //printf("number as input%d\n",n);
    int dec_num = n;

    // counter for binary array 
    int i = 0 ,k ,j ; 
    if (n == 0)
    {
     binNum[i] = 0; 
        //n = n / 2; 
        i++; 
    }
    while (n != 0) { 
        // storing remainder in binary array 
        binNum[i] = n % 2; 
            n = n / 2; 
           i++; 
    } 
     //int j;
    // printing binary array in reverse order 
    for (int j = i - 1 ; j >= 0 ; j--)
        if (i>0)
        {//printf ("dectobin for loop%d",j);
       //printf("The binary equivalent of %d is %d. %d %d\n", dec_num, binNum[j],j,i);
       i--; }
       return binNum;
    }

我编写了一个函数来获取十进制到二进制的符号。这组代码并不返回所有数组值。该函数获得一个十进制值作为输入并返回一个指向包含二进制值的数组的指针。返回的数组不会打印所有值。

0 个答案:

没有答案