-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbestf.c
41 lines (41 loc) · 938 Bytes
/
bestf.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
#include<stdio.h>
#define max 25
int main()
{
int nb,np, b[max],p[max], frag[max],i,j,temp,lowest=10000;
static int bf[max],ff[max];
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of processes:");
scanf("%d",&np);
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 processes:-\n");
for(i=1;i<=np;i++) {
printf("Process %d:",i);
scanf("%d",&p[i]);
}
for(i=1;i<=np;i++) {
for(j=1;j<=nb;j++) {
if(bf[j]!=1){
temp=b[j]-p[i];
if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nProcess_no \tProcess_size \tBlock_no \tBlock_size \tFragment");
for(i=1;i<=np && ff[i]!=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,p[i],ff[i],b[ff[i]],frag[i]);
return 0;
}