Simulate the following disk scheduling algorithms CSCAN

  #include<stdio.h> 

#include<conio.h> 
void main() 

 int size,n,q[20],visit[20],t,head,pos,seek=0,i,j,max,tot=0; 
 float average=0; 
 printf("enter the max range of disk : "); 
 scanf("%d",&size); 
 max=size-1; 
 printf("enter the disk head starting position : "); 
 scanf("%d",&head); 
 printf("enter number of queue elements : "); 
 scanf("%d",&n); 
 printf("enter the work queue : "); 
 for(i=0;i<n;i++) 
 { 
 scanf("%d",&q[i]); 
 visit[i]=0; 
 } 
 for(i=0;i<n;i++) 
 { 
 for(j=i+1;j<n;j++) 
 { 
 if(q[i]>q[j]) 
 { 
 t=q[i]; 
 q[i]=q[j]; 
 q[j]=t; 
 } 
 } 
 } 
 for(i=0;i<n;i++) 
 { 
 if(q[i]>head) 
 { 
 seek=abs(head-q[i]); 
 tot=tot+seek; 
printf("disk head moves from %d to %d with seek 
%d\n",head,q[i],seek); 
 
 visit[i]=1; 
 head=q[i]; 
 } 
 } 
 seek=abs(head-size); 
 tot=tot+seek; 
printf("disk head moves from %d to %d with seek 
%d\n",head,size,seek); 
 head=size; 
 
 seek=abs(size-0); 
 tot=tot+seek; 
printf("disk head moves from %d to %d with seek 
%d\n",size,0,seek); 
 head=0; 
 for(i=0;i<n;i++) 
 { 
 if(visit[i]==0) 
 { 
 seek=abs(head-q[i]); 
 tot=tot+seek; 
printf("disk head moves from %d to %d with seek 
%d\n",head,q[i],seek); 
 visit[i]=1; 
 head=q[i]; 
 } 
 } 
 printf("total seek time : %d\n",tot); 
 average=(float)tot/n; 
 printf("average seek time : %f\n",average); 
 

Comments

Popular posts from this blog

CLOOK DISK SCHEDULING

LOOK Disk Scheduling