-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisksched.c
51 lines (42 loc) · 1.07 KB
/
disksched.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
// FCFS
#include <stdio.h>
void main()
{
int headpos, tracks, maxrange;
printf("Enter the number of tracks: ");
scanf("%d", &tracks);
printf("Enter the headposition: ");
scanf("%d", &headpos);
printf("Enter the maximum range of the disk: ");
scanf("%d", &maxrange);
int trackarr[tracks];
int req[tracks];
for (int i = 0; i < tracks; i++)
{
printf("Enter the track to be traversed: ");
scanf("%d", &trackarr[i]);
req[i] = trackarr[i];
}
printf("%d =>", headpos);
int totalskt = 0;
for (int i = 0; i < tracks; i++)
{
int temp;
if (i < tracks - 1)
{
printf("%d =>", req[i]);
temp = req[i] - req[i + 1];
if (temp < 0)
{
temp *= -1;
}
totalskt += temp;
}
else
{
printf("%d", req[tracks - 1]);
}
}
totalskt = totalskt + (headpos - req[0]);
printf("\nTotal seek time: %d", totalskt);
}