Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int i=0,j=0,count=0,p[3],max=3;
- void Producer()
- {
- p[j]=1;
- j=(j+1)%max;
- ++count;
- printf("\nProducer produces item %d", count);
- }
- void Consumer()
- {
- p[i]=0;
- count--;
- printf("\nConsumer consumes item %d",count+1);
- i=(i+1)%max;
- }
- int main()
- {
- int n;
- while(1){
- printf("\nEnter your choice\n1.Produce\n2.Consume\n");
- scanf("%d",&n);
- switch(n){
- case 1:
- if(count<3)
- Producer();
- else
- printf("Memory full\n");
- break;
- case 2:
- if(count>0)
- Consumer();
- else
- printf("No products to consume\n");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement