-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsstf.c
More file actions
49 lines (31 loc) · 808 Bytes
/
sstf.c
File metadata and controls
49 lines (31 loc) · 808 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
# include<stdio.h>
#include<stdlib.h>
int main()
{
int R[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("enter the number of requests\n");
scanf("%d",&n);
printf("enter the request order\n");
for(i=0;i<n;i++)
scanf("%d",&R[i]);
printf("enter the current(initial) head position\n");
scanf("%d",&initial);
while(count!=n)
{
int min=1000,diff,index;
for(i=0;i<n;i++)
{
diff=abs(R[i]-initial);
if(min>diff)
{
min=diff;
index=i;
}
}
TotalHeadMoment=TotalHeadMoment+min;
initial=R[index];
R[index]=1000;
count++;
}
printf("Total head movement is %d",TotalHeadMoment);
}