-
Notifications
You must be signed in to change notification settings - Fork 0
/
fifo.c
58 lines (45 loc) · 854 Bytes
/
fifo.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>
int main()
{
int p,f,flag;
int miss=0;
int hit=0;
printf("Enter no of pages");
scanf("%d",&p);
printf("Enter no of frames");
scanf("%d",&f);
int pages[p];
int frames[f];
printf("Enter the pages ");
for(int i=0;i<p;i++)
scanf("%d",&pages[i]);
for(int i=0;i<f;i++)
frames[i]=-1;
int fr=0;
for(int i=0;i<p;i++)
{
flag=0;
for(int j=0;j<f;j++)
{
if(pages[i]==frames[j])
{
flag=1;
hit++;
break;
}
}
if(flag==0)
{
frames[fr]=pages[i];
fr=(fr+1)%f;
miss++;
}
printf("Page frame:");
for(int k=0;k<f;k++)
{
printf("%d",frames[k]);
}
}
printf("Total hits are %d\n",hit);
printf("Total miss are %d\n",miss);
}