Skip to content

Instantly share code, notes, and snippets.

@dynamitechetan
Created January 24, 2017 15:01
Show Gist options
  • Save dynamitechetan/83b9014482a53c91f796300c757f0f6b to your computer and use it in GitHub Desktop.
Save dynamitechetan/83b9014482a53c91f796300c757f0f6b to your computer and use it in GitHub Desktop.
#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;
                              }
               }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment