The document presents a C program that implements disk scheduling algorithms by calculating the total and average seek time for a series of disk requests. Users input the number of requests, the disk positions, and the initial head position, after which the program computes the distances and outputs the results. The example provided demonstrates the program's functionality with specific input values.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views2 pages
Os 15
The document presents a C program that implements disk scheduling algorithms by calculating the total and average seek time for a series of disk requests. Users input the number of requests, the disk positions, and the initial head position, after which the program computes the distances and outputs the results. The example provided demonstrates the program's functionality with specific input values.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Sprno:9223
15 IMPLEMENTATION OF VARIOUS DISK SCHEDULING ALGORITHMS
PROGRAM: #include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int n, head, i; float avg_seek_time; printf("Enter the number of requests: "); scanf("%d", &n); if (n <= 0) { printf("The number of requests must be greater than 0.\n"); return 1; } int queue[n]; printf("Enter the queue of disk positions to be read:\n"); for (i = 0; i < n; i++) { scanf("%d", &queue[i]); } printf("Enter the initial head position: "); scanf("%d", &head); int distance = abs(head - queue[0]); // Distance from head to first request for (i = 1; i < n; i++) { distance += abs(queue[i] - queue[i - 1]); // Distance between consecutive requests } avg_seek_time = (float)distance / n; printf("Total seek time = %d\n", distance); printf("Average seek time = %.2f\n", avg_seek_time); return 0; Sprno:9223
} OUTPUT: Enter the number of requests: 4 Enter the queue of disk positions to be read: 98 183 37 122 Enter the initial head position: 100 Total seek time = 318 Average seek time = 79.50