-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathproducer consumer problem.c
25 lines (25 loc) · 1.16 KB
/
producer consumer problem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<stdio.h>
void main()
{
int buffer[10], bufsize, in, out, produce, consume, choice=0; in = 0; out = 0; bufsize = 10;
while(choice !=3)
{
printf(“\n1. Produce \t 2. Consume \t3. Exit”);
printf(“\nEnter your choice: ”);
scanf(“%d”, &choice);
switch(choice)
{
case 1: if((in+1)%bufsize==out) printf(“\nBuffer is Full”);
else {
printf(“\nEnter the value: “);
scanf(“%d”, &produce);
buffer[in] = produce;
in = (in+1)%bufsize;
} Break;
case 2: if(in == out) printf(“\nBuffer is Empty”);
else {
consume = buffer[out];
printf(“\nThe consumed value is %d”, consume);
out = (out+1)%bufsize;
} break;
} } }