What's new

C & C++Help Explain

_KaNeKi_

Established
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 temp,max;
int dloc; //loc of disk in array
clrscr();
printf("enter number of location\t");
scanf("%d",&n);
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;
}

Established

Up

Replies
0
Views
213
Replies
1
Views
183
Replies
2
Views
314
Replies
1
Views
170
Replies
2
Views
160

Members online
1,614
Guests online
2,061
Total visitors
3,675