磁盘调度算法模拟c语言
时间: 2023-12-05 12:39:57 浏览: 86
以下是一个使用FCFS算法模拟磁盘调度的C语言程序:
```c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 1000
int main()
{
int n, i, head, sum = 0, disk[MAX];
float avg;
printf("Enter the number of disk locations: ");
scanf("%d", &n);
printf("Enter the initial position of the disk head: ");
scanf("%d", &head);
printf("Enter the disk queue:\n");
for(i = 0; i < n; i++)
scanf("%d", &disk[i]);
printf("\n");
printf("The disk queue is: ");
for(i = 0; i < n; i++)
printf("%d ", disk[i]);
printf("\n\n");
printf("The disk head starts at %d\n", head);
for(i = 0; i < n; i++)
{
sum += abs(head - disk[i]);
head = disk[i];
}
printf("\nTotal number of track movements = %d\n", sum);
avg = (float)sum / n;
printf("Average track movements = %.1f\n", avg);
return 0;
}
```
阅读全文