Skip to content

Commit fdec5cd

Browse files
authored
first come first serve added
1 parent b42fae1 commit fdec5cd

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

LAB-8/fcfs.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include<bits/stdc++.h>
2+
3+
int main()
4+
{
5+
6+
int n,head,i,j,k,seek=0,max1,diff;
7+
float avg;
8+
9+
printf("enter the max range of disk\n");
10+
scanf("%d",&max1);
11+
12+
printf("enter the size of queue request\n");
13+
scanf("%d",&n);
14+
15+
int queue[n+1];
16+
17+
printf("enter the queue\n");
18+
for(i=1;i<=n;i++)
19+
{
20+
scanf("%d",&queue[i]);
21+
}
22+
23+
printf("enter the initial head position\n");
24+
scanf("%d",&head);
25+
queue[0]=head;
26+
27+
for(j=0;j<=n-1;j++)
28+
{
29+
diff=abs(queue[j+1]-queue[j]);
30+
seek+=diff;
31+
printf("move is from %d to %d with seek %d\n",queue[j],queue[j+1],diff);
32+
}
33+
34+
printf("total seek time is%d\n",seek);
35+
avg=seek/(float)n;
36+
37+
printf("avrage seek time is %f\n",avg);
38+
39+
return 0;
40+
}

0 commit comments

Comments
 (0)