Preview:
#include<stdio.h>

#include<stdlib.h>

int main()

{

 int r[100],i,n,Tst=0,initial,count=0;

printf("Enter the number of Requests\n");

scanf("%d",&n);

printf("Enter the Requests sequence\n");

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

scanf("%d",&r[i]);
  printf("Enter initial head position\n");

scanf("%d",&initial);

 // logic for sstf disk scheduling

 /* loop will execute until all process is completed*/

 while(count!=n)

 {

 int min=1000,d,index;

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

 {

 d=abs(r[i]-initial);

 if(min>d)

 {

 min=d;

 index=i;

 }

 }

Tst=Tst+min;

 initial=r[index];

 // 1000 is for max

 // you can use any number

 r[index]=1000;

 count++;

 }

printf("Total head movement is %d",Tst);

 return 0;
  }
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter