File tree 1 file changed +55
-0
lines changed
1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ //SCAN
2
+
3
+
4
+ #include <conio.h>
5
+ #include <stdio.h>
6
+ int main ()
7
+ {
8
+ int i ,j ,sum = 0 ,n ;
9
+ int d [20 ];
10
+ int disk ; //loc of head
11
+ int temp ,max ;
12
+ int dloc ; //loc of disk in array
13
+ printf ("enter number of location\t" );
14
+ scanf ("%d" ,& n );
15
+ printf ("enter position of head\t" );
16
+ scanf ("%d" ,& disk );
17
+ printf ("enter elements of disk queue\n" );
18
+ for (i = 0 ;i < n ;i ++ )
19
+ {
20
+ scanf ("%d" ,& d [i ]);
21
+ }
22
+ d [n ]= disk ;
23
+ n = n + 1 ;
24
+ for (i = 0 ;i < n ;i ++ ) // sorting disk locations
25
+ {
26
+ for (j = i ;j < n ;j ++ )
27
+ {
28
+ if (d [i ]> d [j ])
29
+ {
30
+ temp = d [i ];
31
+ d [i ]= d [j ];
32
+ d [j ]= temp ;
33
+ }
34
+ }
35
+
36
+ }
37
+ max = d [n ];
38
+ for (i = 0 ;i < n ;i ++ ) // to find loc of disc in array
39
+ {
40
+ if (disk == d [i ]) { dloc = i ; break ; }
41
+ }
42
+ for (i = dloc ;i >=0 ;i -- )
43
+ {
44
+ printf ("%d -->" ,d [i ]);
45
+ }
46
+ printf ("0 -->" );
47
+ for (i = dloc + 1 ;i < n ;i ++ )
48
+ {
49
+ printf ("%d-->" ,d [i ]);
50
+ }
51
+ sum = disk + max ;
52
+ printf ("\nmovement of total cylinders %d" ,sum );
53
+ getch ();
54
+ return 0 ;
55
+ }
You can’t perform that action at this time.
0 commit comments