-
Notifications
You must be signed in to change notification settings - Fork 0
/
12a.c
39 lines (33 loc) · 919 Bytes
/
12a.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
// Disk Scheduling Algorithms
// First Come First Serve
// by Simply
#include <stdio.h>
#include <math.h>
#define MAX 20
void filefcfs(int arr[], int head, int size) {
int seek = 0;
int current, previous = head, distance;
printf("Seek Sequence is\n");
for(int i = 0; i < size; i++) {
current = arr[i];
distance = fabs(previous - current);
seek += distance;
previous = current;
printf("%d-> ", arr[i]);
}
printf("\nTOTAL SEEK OPERATIONS: %d\n", seek);
}
void main() {
int arr[MAX], head, n, i, t;
printf("TOTAL TRACKS: ");
scanf("%d", &t);
printf("TOTAL REQUESTS: ");
scanf("%d", &n);
printf("ENTER TRACK REQUESTS: ");
for(i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
printf("POSITION OF READER / WRITER: ");
scanf("%d", &head);
filefcfs(arr, head, n);
}