-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan.c
More file actions
62 lines (59 loc) · 955 Bytes
/
scan.c
File metadata and controls
62 lines (59 loc) · 955 Bytes
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
59
60
61
62
#include<stdio.h>
int main()
{
int i,j,seek=0,n;
int d[20],temp,disk,dloc;
float avg;
printf("enter the number of loc\t");
scanf("%d",&n);
printf("enter the position of head\t");
scanf("%d",&disk);
printf("enter elements of disk queue\n");
for(i=1;i<n;i++)
{
scanf("%d",&d[i]);
}
d[n]=disk;
d[0]=0;
n=n+1;
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(d[i]>d[j])
{
temp=d[i];
d[i]=d[j];
d[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
if(disk==d[i])
{
dloc=i;
break;
}
}
for(i=0;i<n;i++)
{
printf("%d--->",d[i]);
}
for(i=dloc;i>0;i--)
{
seek=seek+(d[i]-d[i-1]);
printf("\n%d--->%d %d",d[i],d[i-1],seek);
}
printf("\n0--->%d %d",d[dloc+1],seek);
seek=seek+d[dloc+1];
for(i=dloc+1;i<n-1;i++)
{
seek=seek+(d[i+1]-d[i]);
printf("\n%d-->%d %d",d[i],d[i+1],seek);
}
printf("\ntotal seek time:%d",seek);
avg=seek/n;
printf("\nmovement of average seek time %f",avg);
return 0;
}