0% found this document useful (0 votes)
4 views2 pages

DISK

The document is a C program that simulates disk scheduling by accepting user inputs for the number of requests, initial head position, and maximum track limit. It sorts the disk requests and calculates the total and average seek time based on the order of requests served. The program outputs the total seek time and average seek time after processing the disk queue.

Uploaded by

mahigireesh09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

DISK

The document is a C program that simulates disk scheduling by accepting user inputs for the number of requests, initial head position, and maximum track limit. It sorts the disk requests and calculates the total and average seek time based on the order of requests served. The program outputs the total seek time and average seek time after processing the disk queue.

Uploaded by

mahigireesh09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>

void main() {

int d[20], i, n, j, disk, itail, temp, tot = 0, dloc;

float seek = 0, avgs;

printf("Enter the number of requests!: ");

scanf("%d", &n);

d[0] = 0;

printf("Enter the initial head position!: ");

scanf("%d", &disk);

printf("Enter the maximum track limit!: ");

scanf("%d", &itail);

printf("Enter elements of disk queue\n");

for (i = 1; i <= n; i++) {

scanf("%d", &d[i]);

d[n + 1] = disk;

d[n + 2] = itail;

n = n + 3;

for (i = 0; i < n; i++) // sorting disk locations

for (j = i; j < n; j++) {

if (d[i] > d[j]) {

temp = d[i];

d[j] = d[j];

d[j] = temp;

printf("The request queue is\n");

for (i = 0; i < n; i++) {

printf("%d \n", d[i]);


}

for (i = 0; i < n; i++) // to find loc of disc in array

if (disk == d[i]) {

dloc = i;

break;

printf("\nOrder of request served\n");

for (i = dloc; i < n - 1; i++) {

printf("%d ->", d[i]);

tot = d[i + 1] - d[i];

if (tot < 0)

tot = tot * -1;

seek += tot;

for (i = 0; i < dloc - 1; i++) {

printf("%d ->", d[i]);

tot = d[i] - d[i + 1];

if (tot < 0)

tot = tot * -1;

seek += tot;

seek += itail;

avgs = seek / (n - 3);

printf("\n\nTotal Seek time\n: %.2f", seek);

printf("\nAverage seek time\n: %.2f\n\n", avgs);

You might also like