Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

PROGRAM CODE:

#include <stdio.h>

#define MAX_SIZE 10

int buffer[MAX_SIZE];

int in = 0;

int out = 0;

int bufsize = 0;

void produce() {

int produce_value;

if ((in + 1) % MAX_SIZE == out)

printf("\n Buffer is full");

else {

printf("\n Enter the Value:");

scanf("%d", &produce_value);

buffer[in] = produce_value;

in = (in + 1) % MAX_SIZE;

bufsize++;

void consume() {

if (in == out)

printf("\n Buffer is Empty");

else {

int consume_value = buffer[out];


printf("\n The Consumed value is %d", consume_value);

out = (out + 1) % MAX_SIZE;

bufsize--;

int main() {

int choice = 0;

while (choice != 3) {

printf("\n Produce \t Consume \t Exit" );

printf("\n Enter your Choice:");

scanf("%d", &choice);

switch(choice) {

case 1:

produce();

break;

case 2:

consume();

break;

case 3:

break;

default:

printf("\n Invalid Choice");

return 0;

}
OUTPUT:

You might also like