Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- # define buffer 5
- int in=0,out=-1;
- int array[buffer],count=0;
- void Consumer_Function()
- {
- if(count==0){
- printf("array underflow\n");
- return;
- }
- printf("element Consumed is %d\n",array[in]);
- in=(in+1)%buffer;
- count--;
- }
- void Producer_Function()
- {
- int ele;
- if(count==buffer){
- printf("array overflow\n");
- return; }
- scanf("%d",&ele);
- out=(out+1)%buffer;
- array[out]=ele;
- count++;
- }
- void display() {
- int j=in,i;
- if(count==0){
- printf("array is empty\n");
- return;}
- for(i=1;i<=count;i++) {
- printf("%d\t",array[j]);
- j=(j+1)%buffer;
- }
- printf("\n");
- }
- void main() {
- int ch, looper=1;
- printf("1:Produce 2:Consume 3:display default :exit\n");
- while(looper==1){
- printf("enter choice\n");
- scanf("%d",&ch);
- switch(ch){
- case 1: Producer_Function();
- break;
- case 2: Consumer_Function();
- break;
- case 3: display();
- break;
- case 4: looper=0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement