Best Fit Implementation
Do you like this story?
#include
#include
void main()
{
int prs,n,ps[10],i,l,j=10,k,min,d[10];
clrscr();
printf("\nEnter the number of partitions:");
scanf("%d",&n);
printf("\nEnter the size of each partition:");
for(i=0;i
scanf("%d",&ps[i]);
printf("\nEnter the process-size:");
scanf("%d",&prs);
for(i=0;i
d[i]=ps[i]-prs;
printf("\nDifference:");
for(i=0;i
printf("\t%d",d[i]);
for(i=0;i
if(d[i]>=0)
{
min=d[i];
l=i;
break;
}
for(i=l;i
{
if(d[i]<=min)
{
if(d[i]>=0)
{
min=d[i];
k=i;
}
}
}
printf("\n min:%d",min);
if(min>=0)
{
printf("\nThe index to which process is allocated:%d",k);
printf("\nThe size of the partition to which the process
is allocated:%d",ps[k]);
printf("\nExternal fragmentation:%d",ps[k]-prs);
j=1;
if(j==0)
printf("\nProcess size is greater than each of the partition");
}
/*OUTPUT FOR BEST-FIT*/
#include
void main()
{
int prs,n,ps[10],i,l,j=10,k,min,d[10];
clrscr();
printf("\nEnter the number of partitions:");
scanf("%d",&n);
printf("\nEnter the size of each partition:");
for(i=0;i
scanf("%d",&ps[i]);
printf("\nEnter the process-size:");
scanf("%d",&prs);
for(i=0;i
d[i]=ps[i]-prs;
printf("\nDifference:");
for(i=0;i
printf("\t%d",d[i]);
for(i=0;i
if(d[i]>=0)
{
min=d[i];
l=i;
break;
}
for(i=l;i
{
if(d[i]<=min)
{
if(d[i]>=0)
{
min=d[i];
k=i;
}
}
}
printf("\n min:%d",min);
if(min>=0)
{
printf("\nThe index to which process is allocated:%d",k);
printf("\nThe size of the partition to which the process
is allocated:%d",ps[k]);
printf("\nExternal fragmentation:%d",ps[k]-prs);
j=1;
if(j==0)
printf("\nProcess size is greater than each of the partition");
}
INPUT:
Enter the number if partitions: 4
Enter the size of each partition:
16
18
12
11
Enter the process-size: 10
OUTPUT:
Difference: 6 8 2 1
min: 1
The index to which process is allocated: 3
The size of the partition to which the process is allocated: 11
External fragmentation: 1

This post was written by: Rajendra Prasad
Rajendra Prasad is a professional blogger, web designer and front end web developer. Follow him on Facebook