Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. # define buffer 5
  4. int in=0,out=-1;
  5. int array[buffer],count=0;
  6. void Consumer_Function()
  7. {
  8.                if(count==0){
  9.                  printf("array underflow\n");
  10.                  return; 
  11. }
  12.                printf("element Consumed is %d\n",array[in]);
  13.                in=(in+1)%buffer;
  14.                count--;
  15. }
  16. void Producer_Function()
  17. {
  18.                int ele;
  19.                if(count==buffer){
  20.                               printf("array overflow\n");
  21.                return; }
  22.                scanf("%d",&ele);
  23.                out=(out+1)%buffer;
  24.                array[out]=ele;
  25.                count++;
  26. }
  27. void display() {
  28.                int j=in,i;
  29.                if(count==0){
  30.                printf("array is empty\n");
  31.                return;}
  32.                for(i=1;i<=count;i++) {
  33.                printf("%d\t",array[j]);
  34.                j=(j+1)%buffer;
  35. }
  36.                printf("\n");
  37. }
  38. void main() {
  39.                int ch, looper=1;
  40.                printf("1:Produce 2:Consume 3:display default :exit\n");
  41.               while(looper==1){
  42.                               printf("enter choice\n");
  43.                               scanf("%d",&ch);
  44.                               switch(ch){
  45.                               case 1: Producer_Function();
  46.                               break;
  47.                               case 2: Consumer_Function();
  48.                               break;
  49.                               case 3: display();
  50.                               break;
  51.                               case 4: looper=0;
  52.                               }
  53.                }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement