C programming Simulate an example of a FIFO algorithm for op
C programming
Simulate an example of a FIFO algorithm for operating systems.
Solution
Answer:
int front=0,rear=-1;
int a[10],k,i;
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void del();
void add()
{
clrscr();
char x;
while(x!=\'n\')
{
printf(\"enter an integer value\");
scanf(\"%d\",&k);
rear++;
a[rear]=k;
printf(\"has been inserted\ \ wanna enter more(y/n)\");
cin>>x;
}
}
void del()
{
printf(\"%d has been deleted \",a[front]);
for(i=front;i<rear;i++)
{
a[i]=a[i+1];
}
rear--;
getch();
}
void display()
{
clrscr();
for(i=0;i<=rear;i++)
{
printf(\"%d\ \",a[i]);
}
}
void main()
{
clrscr();
int choice;
char e;
while(e!=\'n\')
{
clrscr();
printf(\"1.add\ 2.delete\ 3.display\ \");
printf(\"\ enter your choice\ \");
cin>>choice;
switch(choice)
{
case 1:
add();
break;
case 2:
del();
break;
case 3:
display();
}
printf(\"\ \ wanna enter more for operations(y/n)\");
cin>>e;
}
getch();
}
![C programming Simulate an example of a FIFO algorithm for operating systems.SolutionAnswer: int front=0,rear=-1; int a[10],k,i; #include<stdio.h> #include C programming Simulate an example of a FIFO algorithm for operating systems.SolutionAnswer: int front=0,rear=-1; int a[10],k,i; #include<stdio.h> #include](/WebImages/1/c-programming-simulate-an-example-of-a-fifo-algorithm-for-op-965603-1761494858-0.webp)