0% found this document useful (0 votes)
4 views1 page

Fcfs Disc

This C program calculates the total head movement and average seek time for disk scheduling. It prompts the user to input the number of disk blocks, a disk request string, and the current head position. The program then computes the total head movement and average seek time based on the provided requests.

Uploaded by

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

Fcfs Disc

This C program calculates the total head movement and average seek time for disk scheduling. It prompts the user to input the number of disk blocks, a disk request string, and the current head position. The program then computes the total head movement and average seek time based on the provided requests.

Uploaded by

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

#include <stdio.

h>
#include <stdlib.h>

int main() {
int n;
printf("Enter the total number of disk blocks: ");
scanf("%d", &n);

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

int initial_head_position;
printf("\nEnter the current head position: ");
scanf("%d", &initial_head_position);

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

int total_head_movement = 0;
int current_head_position = initial_head_position;

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


total_head_movement += abs(current_head_position - requests[i]);
current_head_position = requests[i];
}
float Avg_seek_time=0;
Avg_seek_time=total_head_movement/n;
printf("Total head movement: %d\n", total_head_movement);
printf("Avg of seek_time: %f\n", Avg_seek_time);

return 0;
}

You might also like