Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <stdlib.h>
  3. #define n 5
  4. int main()
  5. {
  6. int queue[n],ch=1,front=0,rear=0,i,j=1,x=n, arbitrary[100];
  7. printf("Farmer and Tractors");
  8. printf("\n1.Insert money \n2.Extract money \n3.Display all envelopes \n4.Exit");
  9.  
  10. while(ch)
  11. {
  12. printf("\nEnter the Choice:");
  13. scanf("%d",&ch);
  14. switch(ch)
  15. {
  16. case 1:
  17. if(rear==x)
  18. printf("\n Queue is Full");
  19. else
  20. {
  21. printf("\n Enter no %d envelope:",j++);
  22. scanf("%d",&queue[rear++]);
  23. }
  24. break;
  25. case 2:
  26. if(front==rear)
  27. {
  28. printf("\n Envelope is empty");
  29. }
  30. else
  31. {
  32. printf("\n Money taken: %d",queue[--rear]);
  33. x++;
  34. }
  35. break;
  36. case 3:
  37. printf("\n Envelope Elements are:\n ");
  38. if(front==rear)
  39. printf("\n Envelope is Empty");
  40. else
  41. {
  42. for(i=front; i<rear; i++)
  43. {
  44. printf("%d",queue[i]);
  45. printf("\n");
  46. arbitrary[i++];
  47. }
  48. }
  49. break;
  50. case 4:
  51. exit(0);
  52. default:
  53. printf("Wrong");
  54. }
  55. }
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement