-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbf.c
More file actions
62 lines (48 loc) · 1.37 KB
/
Copy pathbf.c
File metadata and controls
62 lines (48 loc) · 1.37 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
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
int main() {
int processSize[100], blockSize[100];
int n, m, best;
int allocated[100];
printf("Enter the number of process : ");
scanf("%d", &n);
printf("Enter the number of block : ");
scanf("%d", &m);
printf("Enter process size\n");
for (int i = 0; i < n; i++) {
scanf("%d", &processSize[i]);
}
printf("Enter block size\n");
for (int i = 0; i < m; i++) {
scanf("%d", &blockSize[i]);
}
for(int i = 0; i < n; i++) {
allocated[i] = -1;
}
for (int i = 0; i < n; i++) {
best = -1;
for(int j = 0; j < m; j++) {
if(blockSize[j] >= processSize[i]) {
if(best == -1 || blockSize[j] < blockSize[best]) {
best = j;
}
}
}
if(best != -1) {
allocated[i] = best;
blockSize[best] -= processSize[i];
}
}
printf("\nP.No\tP.Size\tB.No\tB.Size\tFragment\n");
for(int i=0;i<n;i++) {
if(allocated[i] != -1)
printf("%d\t%d\t%d\t%d\t%d\n",
i+1,
processSize[i],
allocated[i]+1,
processSize[i] + blockSize[allocated[i]],
blockSize[allocated[i]]);
else
printf("%d\t%d\tNot Allocated\n", i+1, processSize[i]);
}
return 0;
}