Alx09

Untitled

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