Advertisement
Alx09

tot probelma

Apr 26th, 2021
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. unsigned short  st[11], varf;
  4.  
  5. void push(unsigned short x) {
  6.     if (varf > 9) return;
  7.     st[++varf] = x;
  8.    
  9.        
  10. }
  11.  
  12. void pop() {
  13.     if (varf == 0) return;
  14.     unsigned short copie = st[varf], nrBit = 0;
  15.     while (copie) {
  16.         nrBit++;
  17.         copie &= copie - 1;
  18.     }
  19.     copie = st[varf];
  20.     printf("pop %ld\n", st[varf]);
  21.     printf("Numarul de biti = 1: %hd\n", nrBit);
  22.     copie &= ~(1 << 2);
  23.     printf("Numarul dupa mascarea bitului 2: %hd\n", copie);
  24.     st[varf] &= ~(1 << 6);
  25.     printf("Numarul dupa bitul 6 devine 0: %hd\n\n", st[varf]);
  26.     varf--;
  27. }
  28.  
  29. int main(){
  30.     unsigned short x, i;
  31.     for (i = 1; i < 8; i++) {
  32.         printf("st[%d]= ", i);
  33.         scanf("%hd", &x);
  34.         push(x);
  35.     }
  36.     for (i = 1; i < 8; i++)pop();
  37.    
  38.  
  39.    
  40.  
  41.     return 0;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement