#include<stdio.h>
#include<conio.h>
#include<math.h>
#define max 20
#define cymax 199
int i,req,ttl_tracks=0,cposn;
int cyposn[max];
void input()
{
do
{
clreol();
printf("\n Enter the current header position : ");
scanf("%d",&cposn);
}while(cposn>cymax || cposn <=0);
printf("\n Enter the %d I/O Requests : ",req);
cyposn[0] = cposn;
for(i=1;i<=req;i++)
scanf("%d",&cyposn[i]);
}
void FCFS()
{
printf("\nS.No. Current Position Next Position Displacement \n");
printf("---------------------------------------------------------- \n\n");
for(i=0;i<req;i++)
{
printf(" %d\t\t%d\t\t%d\t\t%d\n",i+1,cyposn[i],cyposn[i+1],abs(cyposn[i]-cyposn[i+1]));
ttl_tracks += (abs(cyposn[i]-cyposn[i+1]));
}
printf("---------------------------------------------------------- \n\n");
printf(" Total Tracks Displaced : %d",ttl_tracks);
}
void main()
{
do
{
clrscr();
printf("\n Enter the number of requests : ");
scanf("%d",&req);
}while(req>max || req <=0);
input();
FCFS();
getch();
}
No comments:
Post a Comment