Advertisement
olekturbo

SPR2/POPRAWIONE

Mar 27th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void Blad(int);
  5. int SpakujLiczbe(int, int, int, int);
  6.  
  7. int main() {
  8.  
  9. int a, b, c, d;
  10.  
  11. scanf("%i", &a);
  12. scanf("%i", &b);
  13. scanf("%i", &c);
  14. scanf("%i", &d);
  15.  
  16. if(a < 0 || a >= 256) Blad(a);
  17. else if(b < 0 || b >= 256*256) Blad(b);
  18. else if(c < 0 || c >= 2) Blad(c);
  19. else if(d < 0 || d >= 128) Blad(d);
  20.  
  21. printf("Spakowana liczba to: %i ", SpakujLiczbe(a,b,c,d));
  22.  
  23. }
  24.  
  25. void Blad(int x) {
  26.  
  27. printf("Liczba %i jest niepoprawna!", x);
  28. exit(1);
  29.  
  30. }
  31.  
  32. int SpakujLiczbe(int a, int b, int c, int d) {
  33.  
  34.  
  35. int wynik = 0;
  36. wynik<<=8;
  37. wynik|=a;
  38. wynik<<=16;
  39. wynik|=b;
  40. wynik<<=1;
  41. wynik|=c;
  42. wynik<<=7;
  43. wynik|=d;
  44.  
  45. return wynik;
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement