Advertisement
lukasd

zadanie 2 zestaw 15

Dec 19th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. void set(char arr[], int i, bool v)
  2. {
  3.     char temp = arr[i / 8];
  4.     char pos = 1 << (i % 8);
  5.     printf("%d", pos);
  6.     if (v)
  7.     {
  8.         temp = temp | pos;
  9.     }
  10.     else
  11.     {
  12.         pos = ~pos;
  13.         temp = temp&pos;
  14.     }
  15.     arr[i / 8] = temp;
  16. }
  17. bool get(char arr[], int i)
  18. {
  19.     char pos = 1 << (i % 8);
  20.     return arr[i / 8] & pos;
  21. }
  22. void kolos1()
  23. {
  24.     char arr[10];
  25.     set(arr, 10, true);
  26.     set(arr, 11, true);
  27.     for (int i = 0; i < 80; i++)
  28.     {
  29.         printf("%c",get(arr,i)?'+':'-');
  30.     }
  31.     puts("");
  32.     set(arr, 10, false);
  33.     for (int i = 0; i < 80; i++)
  34.     {
  35.         printf("%c", get(arr, i) ? '+' : '-');
  36.     }
  37.    
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement