-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathdisk cscan.c
More file actions
47 lines (47 loc) · 918 Bytes
/
disk cscan.c
File metadata and controls
47 lines (47 loc) · 918 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
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,h,distance=0,head,temp,track,i,j;
printf("Enter the no of requests\n");
scanf("%d",&n);
printf("Enter the request order\n");
int req[n];
for(i=0;i<n;i++)
scanf("%d",&req[i]);
printf("Enter head position\n");
scanf("%d",&h); head=h;
printf("Enter the total no of tracks\n");
scanf("%d",&track);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(req[i]<req[j])
{temp=req[j];
req[j]=req[i];
req[i]=temp;}
}
}
int position;
for(i=0;i<n;i++)
{
if(req[i]>h)
{
position=i;break;
}
}
distance=(((track-1)-head)+((track-1)-0)+(req[position-1]-0));
printf("Service Order:");
printf("%d->",head);
for(i=position;i<n;i++){
if(req[i]!=head)
printf("%d->",req[i]);}
printf("%d->",track-1);
printf("%d->",0);
for(i=0;i<position-1;i++)
printf("%d->",req[i]);
printf("%d",req[position-1]);
printf("\nTotal seek time=%d",distance);
printf("\nAverage seek time=%f",((float)distance/n));
}