Advertisement
Patey

Untitled

Apr 13th, 2021
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3.  
  4. void push(int x, int *vf, int *st)
  5. {
  6.     (*vf)++;
  7.     st[*vf] = x;
  8. }
  9.  
  10. int pop(int *vf, int *st)
  11. {
  12.     (*vf)--;
  13.     return st[(*vf) + 1];
  14. }
  15.  
  16. int stiva_goala(int *vf, int *st)
  17. {
  18.     if ((*vf) == -1)
  19.         return 0;
  20.     else
  21.         return 1;
  22. }
  23.  
  24. int main()
  25. {
  26.     int c, n,vf=-1,st[100],i,x;
  27.  
  28.     printf("n= ");
  29.     scanf("%d", &n);
  30.  
  31.     do {
  32.         printf("C= ");
  33.         scanf("%d", &c);
  34.     } while ((c < 0) || (c > 7));
  35.  
  36.     for (i = 0; i < n; i++)
  37.     {
  38.         printf("Elementul cu numarul %d este: ", i + 1);
  39.         scanf("%d", &x);
  40.         if ((x >> c) & 1)
  41.         {
  42.             push(x, &vf, st);
  43.         }
  44.     }
  45.  
  46.     do {
  47.         printf("%d ",pop(&vf, st));
  48.     } while (stiva_goala(&vf, st) == 1);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement