Advertisement
Denis_Hristov

DecimalToBinary

Mar 15th, 2024
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void toBinary(int* a){
  5.     int binaryNum[16];
  6.  
  7.     int i = 0;
  8.  
  9.     while (*a > 0) {
  10.         binaryNum[i] = *a % 2;
  11.  
  12.         *a = *a / 2;
  13.  
  14.         i++;
  15.     }
  16.  
  17.     for (int j = i - 1; j >= 0; j--) {
  18.         printf("%d", binaryNum[j]);
  19.     }
  20. }
  21.  
  22.  
  23. int main()
  24. {
  25.     int a = 358;
  26.  
  27.     toBinary(&a);
  28.  
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement