Convert decimal to binary in C

后端 未结 16 746
攒了一身酷
攒了一身酷 2020-12-10 09:38

I am trying to convert a decimal to binary such as 192 to 11000000. I just need some simple code to do this but the code I have so far doesn\'t work:

void de         


        
16条回答
  •  感情败类
    2020-12-10 10:01

    int main() 
    { 
     int n, c, k;
     printf("Enter an integer in decimal number system: ");
     scanf("%d", &n);
     printf("%d in binary number system is: ", n);
     for (c = n; c > 0; c = c/2) 
      {
       k = c % 2;//To
       k = (k > 0) ? printf("1") : printf("0");
      }
     getch();
     return 0; 
    }
    

提交回复
热议问题