olekturbo

spr2

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