-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathbest_fit.c
57 lines (43 loc) · 1.15 KB
/
best_fit.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
46
47
48
49
50
51
52
53
54
55
56
57
#include<stdio.h>
int i,j;
void bestfit(int[],int[],int,int);
void main()
{
int block[10],process[10],p_no,b_no;
printf("Enter the number of processes: ");
scanf("%d",&p_no);
printf("Enter the memory required for process:-");
for (i=0;i<p_no;i++)
{
printf("\nProcess ID = %d -- ",i);
scanf("%d",&process[i]);
}
printf("\nEnter the number of memory blocks: ");
scanf("%d",&b_no);
printf("Enter the memory blocks:\n");
for(i=0;i<b_no;i++)
scanf("%d",&block[i]);
bestfit(process,block,p_no,b_no);
}
void bestfit(int process[],int block[],int p_no,int b_no)
{
int index;
printf("Process ID\tStatus\t\tBlock Number\n");
for(i=0;i<p_no;i++)
{
index=-1;
for(j=0;j<b_no;j++)
if(block[j]>=process[i])
{
if(index==-1 || block[index]>block[j])
index=j;
}
if(index==-1)
printf("%d\t\tNot allocated\t----\n",i);
else
{
block[index]-=process[i];
printf("%d\t\tAllocated\t%d\n",i,index);
}
}
}