Advertisement
JuliaPopadowska

zad 2/10 PN

Apr 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. char vchar()
  5. {
  6.     char cc;
  7.     while ((cc = getchar()) <= ' ');
  8.     return cc;
  9. }
  10.  
  11. int main()
  12. {
  13.     unsigned long long x , maska=0x8000000000000000;
  14.     bool dalej = true;
  15.     char opcja;
  16.     int i = 63,j=0;
  17.     while (dalej)
  18.     {
  19.         printf("Podaj opcje: ");
  20.         opcja = vchar();
  21.         switch (opcja & 0x5F)
  22.         {
  23.         case 'N': scanf("%llu", &x); break;
  24.  
  25.         case 'L':
  26.         {
  27.             while (i > 0)
  28.             {
  29.                 if ((x & maska) !=0)
  30.                 {
  31.                     printf("%d\n", i);
  32.                     break;
  33.                 }
  34.                 x <<= 1;
  35.                 i--;
  36.             }
  37.             break;
  38.         }
  39.         case 'R':
  40.         {
  41.             while (j<63)
  42.             {
  43.                 if ((x & 1) == 0)
  44.                 {
  45.                     printf("%d \n", j);
  46.                         break;
  47.                 }
  48.                 x >>= 1;
  49.                 j++;
  50.             }
  51.             break;
  52.         }
  53.         case 'Q': return 0; break;
  54.         }
  55.     }
  56.  
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement