Advertisement
Guest User

es 8.1

a guest
Oct 21st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4. // algoritmo senza usare un array
  5. int b1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0,b8=0,n,coden;
  6.  
  7. printf("Inserire un numero positivo tra 0 e 255\n");
  8. coden=scanf("%d",&n);
  9.  
  10. if((n<0)||(n>255)||(coden!=1)){
  11. printf("Valore non valido\n");
  12. return 1;
  13. }
  14.  
  15. b8=n%2;
  16. n=n/2;
  17. b7=n%2;
  18. n=n/2;
  19. b6=n%2;
  20. n=n/2;
  21. b5=n%2;
  22. n=n/2;
  23. b4=n%2;
  24. n=n/2;
  25. b3=n%2;
  26. n=n/2;
  27. b2=n%2;
  28. n=n/2;
  29. b1=n%2;
  30.  
  31. printf("In binario è: %d%d%d%d%d%d%d%d \n",b1,b2,b3,b4,b5,b6,b7,b8);
  32. return 0;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement