What's new

C & C++ Help Explain

_KaNeKi_

Established
Joined
Jan 15, 2017
Posts
882
Solutions
1
Reaction
139
Age
23
mga maam/sir im studying c language po ngayon. medyo nahihirapan po ako. then binigyan kami ng task to explain a program. papatulong po sana ako magpa explain dito sa code na to. itong program na to is for disk scheduling (Scan scheduling). salamat po mga maam/sir.

eto po yung code:


#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,sum=0,n;
int d[20];
int disk; //loc of head
int temp,max;
int dloc; //loc of disk in array
clrscr();
printf("enter number of location\t");
scanf("%d",&n);
printf("enter position of head\t");
scanf("%d",&disk);
printf("enter elements of disk queue\n");
for(i=0;i<n;i++)
{
scanf("%d",&d);
}
d[n]=disk;
n=n+1;
for(i=0;i<n;i++) // sorting disk locations
{
for(j=i;j<n;j++)
{
if(d>d[j])
{
temp=d;
d=d[j];
d[j]=temp;
}
}

}
max=d[n];
for(i=0;i<n;i++) // to find loc of disc in array
{
if(disk==d) { dloc=i; break; }
}
for(i=dloc;i>=0;i--)
{
printf("%d -->",d);
}
printf("0 -->");
for(i=dloc+1;i<n;i++)
{
printf("%d-->",d);
}
sum=disk+max;
printf("\nmovement of total cylinders %d",sum);
getch();
return 0;
}
 
Top