Write a simulation program for disk scheduling using FCFS algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request order in which it is served. Also display the total number of head movements.
Write a simulation program for disk scheduling using FCFS algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request order in which it is served. Also display the total number of head movements.
Program:
#include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int ap[50],i,th,n,cp; printf("\nEnter the number of memory blocks:"); scanf("%d",&n); printf("\nEnter the current position:"); scanf("%d",&cp); printf("\nEnter request string:"); for(i=0;i<n;i++){ scanf("%d",&ap[i]); } th=0; for(i=0;i<n;i++){ if(cp>ap[i]){ th+=cp-ap[i]; cp=ap[i]; } else{ th+=ap[i]-cp; cp=ap[i]; } printf(" %d",ap[i]); } printf("\nTotal head movements:%d",th); }
Comments
Post a Comment