Advertisement
luizaspan

Teste vetores (binariando)

May 28th, 2015
368
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. // binariando
  4.  
  5. int main(void)
  6. {
  7.   int dec=1024,i,x[15];
  8.   printf("%d %d \n",dec/10,dec%10);
  9.  
  10.   for (i=0;i<15;i++)
  11.     {
  12.       // printf("%d \t",dec%10);
  13.       // imprime o número ao contrário => como resolver? armazenar num vetor
  14.       x[i]=dec%2;
  15.       dec=dec/2;
  16.     }
  17.  
  18.    for(i=14;i>=0;i--)
  19.     printf("%d",x[i]);
  20.  
  21.    printf("\n");
  22.  
  23.   return 0;
  24. }
  25.  
  26.  
  27. // 1. declarar os valores de x
  28. // 2. armazenar num vetor
  29. // 3. imprimir em ordem reversa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement