#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("Enter the number of Requests
");
scanf("%d",&n);
printf("Enter the Requests sequence
");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position
");
scanf("%d",&initial);
// logic for sstf disk scheduling
/* loop will execute until all process is completed*/
while(count!=n)
{
int min=INT_MAX,d,index;
for(i=0;i<n;i++)
{
d=abs(RQ[i]-initial);
if(min>d)
{
min=d;
index=i;
}
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
// 1000 is for max
// you can use any number
RQ[index]=INT_MAX;
count++;
}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}
Code Example |
---|
C :: c random list |
C :: space after format specifiers in c |
C :: zizag c |
C :: random number in c |
C :: reading string with spaces in c |
C :: execution time of c program |
C :: rl_replace_line |
C :: c data types |
C :: how to convert string to integer in c |
C :: is it possible to access argv in function |
C :: Successeur récurssive |
C :: input in c |
C :: strcasecmp in c |
C :: find smallest number in array in c |
C :: how to sleep in c |
C :: c fork wait for child |
C :: c check if char is an operator |
C :: how do you make a copy of a linked list in c |
C :: c program to print the multiplication table |
C :: toupper function in c |
C :: sleep function in c |
C :: remove string from string c |
C :: convert c program to assembly language online |
C :: fgets c |
C :: dynamic memory allocation c |
C :: actionbar content color in android |
C :: pygramid program in c |
C :: increment and decrement operator |
C :: c programming exercises |
C :: c comment |