-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcfsdisk.c
33 lines (33 loc) · 892 Bytes
/
fcfsdisk.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
#include<stdio.h>
void main(){
int i,n,count=0,difference,head,a[100],size;
//Enter number of requests and head
printf("Enter number of requests: ");
scanf("%d",&n);
printf("Enter head: ");
scanf("%d",&head);
printf("Enter disk size: ");
scanf("%d",&size);
printf("Enter %d cylinder requests:\n",n);
//Accept cylinder numbers
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
}
a[0]=head;
//compute total seek operations
for ( i = 0; i <= n; i++)
{
difference=abs(a[i]-head);
count=count+difference;
head=a[i];
}
//display seek sequence
printf("Seek Sequence :\n");
for ( i = 0; i <= n; i++)
{
printf("%d ",a[i]);
}
//display total and average seek operations
printf("\nTotal: %d",count);
printf("\nAverage: %f",(float)(count)/n);
}