/*CSEMATTER.BLOGSPOT.IN
C PROGRAM TO IMPLEMENT FCFS DISK SCHEDULING ALGO*/
#include<stdio.h>
#include<conio.h>
void main()
{
int queue[20],n,head,i,j,k,seek=0,max,diff;
float aver;
clrscr();
printf("enter the max range of disk");
scanf("%d",&max);
printf("enter the size of queue request");
scanf("%d",&n);
printf("enter the queue");
for(i=1;i<=n;i++)
{scanf("%d",&queue[i]);}
printf("enter the initial head position");
scanf("%d",&head);
queue[0]=head;
for(j=0;j<=n-1;j++)
{
diff=abs(queue[j+1]-queue[j]);
seek+=diff;
printf("move is from %d to %d with seek %d\n",queue[j],queue[j+1],diff);
}
printf("total seek time is%d\n",seek);
aver=seek/(float)n;
printf("avrage seek time is %f\n",aver);
getch();
}
/*OUTPUT:
enter the max range of disk180
enter the size of queue request8
enter the queue87
170
40
150
36
72
66
15
enter the initial head position60
move is from 60 to 87 with seek 27
move is from 87 to 170 with seek 83
move is from 170 to 40 with seek 130
move is from 40 to 150 with seek 110
move is from 150 to 36 with seek 114
move is from 36 to 72 with seek 36
move is from 72 to 66 with seek 6
move is from 66 to 15 with seek 51
total seek time is557
avrage seek time is 69.625000
*/
C PROGRAM TO IMPLEMENT FCFS DISK SCHEDULING ALGO*/
#include<stdio.h>
#include<conio.h>
void main()
{
int queue[20],n,head,i,j,k,seek=0,max,diff;
float aver;
clrscr();
printf("enter the max range of disk");
scanf("%d",&max);
printf("enter the size of queue request");
scanf("%d",&n);
printf("enter the queue");
for(i=1;i<=n;i++)
{scanf("%d",&queue[i]);}
printf("enter the initial head position");
scanf("%d",&head);
queue[0]=head;
for(j=0;j<=n-1;j++)
{
diff=abs(queue[j+1]-queue[j]);
seek+=diff;
printf("move is from %d to %d with seek %d\n",queue[j],queue[j+1],diff);
}
printf("total seek time is%d\n",seek);
aver=seek/(float)n;
printf("avrage seek time is %f\n",aver);
getch();
}
/*OUTPUT:
enter the max range of disk180
enter the size of queue request8
enter the queue87
170
40
150
36
72
66
15
enter the initial head position60
move is from 60 to 87 with seek 27
move is from 87 to 170 with seek 83
move is from 170 to 40 with seek 130
move is from 40 to 150 with seek 110
move is from 150 to 36 with seek 114
move is from 36 to 72 with seek 36
move is from 72 to 66 with seek 6
move is from 66 to 15 with seek 51
total seek time is557
avrage seek time is 69.625000
*/
Thanks for nice post.C programming details here
ReplyDeleteget me the errors faced during the coding
ReplyDeleteYour question is not clear????
DeleteThis comment has been removed by the author.
ReplyDeleteGood Job !
ReplyDeleteWelcome to My Blog
Meaning of seek in this program
ReplyDelete