Alx09

Untitled

Apr 26th, 2021
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 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.     printf("pop %ld\n", st[varf]);
  20.     printf("Numarul de biti = 1: %ld\n", nrBit);
  21.     printf("Numarul dupa mascarea bitului 2: \n");
  22.     st[varf] &= ~(1 << 6);
  23.     printf("Numarul dupa bitul 6 devine 0: %ld\n\n", st[varf]);
  24.     varf--;
  25. }
  26.  
  27. int main(){
  28.     unsigned short x, i;
  29.     for (i = 1; i < 8; i++) {
  30.         printf("st[%d]= ", i);
  31.         scanf("%hd", &x);
  32.         push(x);
  33.     }
  34.     for (i = 1; i < 8; i++)pop();
  35.    
  36.  
  37.    
  38.  
  39.     return 0;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment