You are on page 1of 1

visit-www.Codes2u.

com
#include<stdio.h> #include<conio.h> #include<math.h> void main() {int dq[30],i,j,m,hd,cyl,mv,tmv=0,min,temp; clrscr(); printf("enter the total no of cyllinderes:"); scanf("%d",&cyl); printf("\nenter the no of cyllinders in disk queue:"); scanf("%d",&m); printf("\nenter the referenc disk queue:"); for(i=1;i<=m;i++) scanf("%d",&dq[i]); printf("\nenter the initial head value:"); scanf("%d",&hd); dq[0]=hd; for(i=0;i<m;i++) {min=cyl; for(j=i+1;j<=m;j++) if(min>abs(dq[i]-dq[j])) {min=abs(dq[i]-dq[j]); temp=dq[i+1]; dq[i+1]=dq[j]; dq[j]=temp; } mv=abs(dq[i+1]-dq[i]); printf("%d ",mv); tmv+=mv; } printf("\ntotal head movement:%d",tmv); getch(); }

You might also like