-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock_files.c
More file actions
50 lines (41 loc) · 1.25 KB
/
Copy pathblock_files.c
File metadata and controls
50 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#define MAX 25
#define INITIAL_LOWEST 10000
int main() {
int frag[MAX], b[MAX], f[MAX];
int i, j, nb, nf, temp, lowest = INITIAL_LOWEST;
static int bf[MAX], ff[MAX];
printf("\nEnter the number of blocks:");
scanf("%d", &nb);
printf("Enter the number of files:");
scanf("%d", &nf);
printf("\nEnter the size of the blocks:-\n");
for (i = 1; i <= nb; i++) {
printf("Block %d:", i);
scanf("%d", &b[i]);
}
printf("Enter the size of the files :-\n");
for (i = 1; i <= nf; i++) {
printf("File %d:", i);
scanf("%d", &f[i]);
}
for (i = 1; i <= nf; i++) {
for (j = 1; j <= nb; j++) {
if (bf[j] != 1) {
temp = b[j] - f[i];
if (temp >= 0 && temp < lowest) {
ff[i] = j;
lowest = temp;
}
}
}
frag[i] = lowest;
bf[ff[i]] = 1;
lowest = INITIAL_LOWEST;
}
printf("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment");
for (i = 1; i <= nf && ff[i] != 0; i++) {
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", i, f[i], ff[i], b[ff[i]], frag[i]);
}
return 0;
}