0% found this document useful (0 votes)
10 views2 pages

Program of Best Fit

The document is a C program that implements the Best Fit algorithm for memory allocation. It prompts the user to input the number of memory blocks and their sizes, as well as the number of processes and their sizes. The program allocates processes to the best fitting blocks and reports unallocated processes.

Uploaded by

deorechanchal2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Program of Best Fit

The document is a C program that implements the Best Fit algorithm for memory allocation. It prompts the user to input the number of memory blocks and their sizes, as well as the number of processes and their sizes. The program allocates processes to the best fitting blocks and reports unallocated processes.

Uploaded by

deorechanchal2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

//Program of Best Fit

#include<stdio.h>
int main()
{
int a[20],p[20],i,j,n,m;
printf("Enter no. of Blocks.\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the %dst Block size:",i);
scanf("%d",&a[i]);
}

printf("Enter no. of Processes.\n");


scanf("%d",&m);
for(i=0;i<m;i++)
{
printf("Enter the size of %dst Process:",i);
scanf("%d",&p[i]);
}

for(int i = 0; i<n; i++){


for(int j = i+1; j<n; j++){
if(a[i] > a[j]){
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}

for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(p[j]<=a[i])
{
printf("The Process %d allocated to %d\n",j,a[i]);
p[j]=10000;
break;
}
}
}

for(j=0;j<m;j++)
{
if(p[j]!=10000)
{
printf("The Process %d is not allocated\n",j);
}
}
}

Output:-

You might also like