-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathff.c
More file actions
54 lines (44 loc) · 1.24 KB
/
Copy pathff.c
File metadata and controls
54 lines (44 loc) · 1.24 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
#include <stdio.h>
int main() {
int processSize[100], blockSize[100];
int n, m;
int allocation[100];
printf("Enter the number of process : ");
scanf("%d", &n);
printf("Enter the number of blocks : ");
scanf("%d", &m);
printf("Enter the size of process\n");
for(int i = 0; i < n; i++) {
scanf("%d", &processSize[i]);
}
printf("Enter the block size\n");
for(int i = 0; i < m; i++) {
scanf("%d", &blockSize[i]);
}
for(int i = 0; i < n; i++) {
allocation[i] = -1;
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++){
if(blockSize[j] >= processSize[i]) {
allocation[i] = j;
blockSize[j] -= processSize[i];
break;
}
}
}
printf("\nP.No\tP.Size\tB.No\tB.Size\tFragments\n");
for (int i = 0; i < n; i++) {
if (allocation[i] != -1) {
printf("%d\t%d\t%d\t%d\t%d\n",
i+1,
processSize[i],
allocation[i]+1,
processSize[i] + blockSize[allocation[i]],
blockSize[allocation[i]]);
} else {
printf("%d\t%d\tNot Allocated\n", i+1, processSize[i]);
}
}
return 0;
}