Monday 7 August 2017

fcfs_disk.java (OS)

#include<stdio.h>
#include<math.h>
int main()
{
    int n,tr[10],head,total,i,j;
    printf("entre the number of request: ");
    scanf("%d",&n);
   
    printf("entre the track number: ");
    for(i=0;i<n;i++)
    {
    scanf("%d",&tr[i]);
    }
    //printf("%d",tr[i]);
    printf("entre the initial head position: ");
    scanf("%d",&head);
    for(j=0;j<n;j++)
    {
        total = total + abs(tr[j]-head);
        head=tr[j];
        }
        printf("Total head movement: %d ",total);
       
   
    return 0;
}

/*
Output:

entre the number of request: 5
entre the track number: 20
30
40
50
60
entre the initial head position: 20
Total head movement: 40
*/

No comments:

Post a Comment