-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirstfit.c
45 lines (39 loc) · 1.06 KB
/
firstfit.c
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
#include <stdio.h>
void main()
{
int blocknum, processnum;
printf("Enter the number of blocks: ");
scanf("%d", &blocknum);
printf("Enter the number of process: ");
scanf("%d", &processnum);
int blockarr[blocknum], processarr[processnum];
for (int i = 0; i < blocknum; i++)
{
printf("Enter the size of the memory blocks: ");
scanf("%d", &blockarr[i]);
}
for (int i = 0; i < processnum; i++)
{
printf("Enter the process: ");
scanf("%d", &processarr[i]);
}
for (int i = 0; i < processnum; i++)
{
int allocflag;
for (int j = 0; j < blocknum; j++)
{
allocflag = 0;
if (processarr[i] <= blockarr[j])
{
printf("process %d block %d\n", i + 1, j + 1);
blockarr[j] = 0;
allocflag = 1;
break;
}
}
if (allocflag == 0)
{
printf("process %d cannot be allocated\n", i + 1);
}
}
}