Advertisement
rdsedmundo

decimal -> binário.c

May 9th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     int num, aux, i = 0, numAlg=0;
  5.  
  6.     printf("Digite um numero na base decimal: ");
  7.     scanf("%d", &num);
  8.  
  9.     aux = num;
  10.     while(aux > 0) {
  11.         aux /= 10;
  12.         numAlg++;
  13.     }
  14.  
  15.     int bin[numAlg*4];
  16.  
  17.     aux = num;
  18.     while(aux > 0) {
  19.         bin[i] = aux%2;
  20.         aux /= 2;
  21.         i++;
  22.     }
  23.  
  24.     printf("\nDecimal: %d\nBinario: ", num);
  25.  
  26.     for(int j = i-1; j >= 0; j--) printf("%d", bin[j], i);
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement