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

Back To Back

The document outlines a simulation program for disk scheduling using the FCFS algorithm. It prompts the user for the total number of disk requests, the request string, and the current head position, then calculates and displays the order of requests served and the total head movements. An example output demonstrates the program's functionality with specific input values.

Uploaded by

Reshma Maner
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)
3 views2 pages

Back To Back

The document outlines a simulation program for disk scheduling using the FCFS algorithm. It prompts the user for the total number of disk requests, the request string, and the current head position, then calculates and displays the order of requests served and the total head movements. An example output demonstrates the program's functionality with specific input values.

Uploaded by

Reshma Maner
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

PRACTICAL 2:

Write a simulation program for disk scheduling using FCFS algorithm. Accept total number of disk
blocks, disk request string, and current head position from the user. Display the list of request in the
order in which it is served. Also display the total number of head moments.
55, 58, 39, 18, 90, 160, 150, 38, 184
Start Head Position: 50

#include <stdio.h>
#include <stdlib.h> // Include this to use the abs function

int main() {
int n; // Number of disk requests
int requests[100]; // Array to store disk requests
int currentHead; // Current head position
int totalHeadMovements = 0; // Total head movements

// Input the number of requests


printf("Enter the total number of disk requests: ");
scanf("%d", &n);

// Input the disk request string


printf("Enter the disk request string (space-separated): ");
for (int i = 0; i < n; i++) {
scanf("%d", &requests[i]);
}

// Input the starting head position


printf("Enter the Start Head Position: ");
scanf("%d", &currentHead);

// Displaying the order of requests served


printf("Order of requests served: \n");

// Serve the requests in the order they were entered


for (int i = 0; i < n; i++) {
printf("%d ", requests[i]);

// Calculate head movement


totalHeadMovements += abs(currentHead - requests[i]);
currentHead = requests[i]; // Move the head to the current request
}

// Display total head movements


printf("\nTotal Head Movements: %d\n", totalHeadMovements);

return 0;
}

OUTPUT:-
Enter the total number of disk requests: 9
Enter the disk request string (space-separated): 55 58 39 18 90 160 150 38 184
Enter the Start Head Position: 50
Order of requests served:
55 58 39 18 90 160 150 38 184
Total Head Movements: 458

You might also like