Patey

Untitled

Apr 13th, 2021
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.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 main()
  17. {
  18.     int n, i, a,st[8],j,aux,vf=-1;
  19.     printf("Dati numarul de numere: ");
  20.     scanf("%d", &n);
  21.     for (i = 0; i < n; i++)
  22.     {
  23.         printf("Dati o noua valoare ");
  24.         scanf("%d", &a);
  25.         for (j = 7; j >= 0; j--)
  26.         {
  27.             aux = (a >> j) & 1;
  28.             printf("%d", aux);
  29.             push(aux, &vf, st);
  30.         }
  31.         printf("\n");
  32.         for (j = 0; j <= 7; j++)
  33.         {
  34.             aux = pop(&vf, st);
  35.             printf("%d", aux);
  36.         }
  37.         printf("\n\n");
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment