Implementation of Worst-Fit Algorithm Coding: #Include Main
Implementation of Worst-Fit Algorithm Coding: #Include Main
CODING:
#include<stdio.h>
main()
{
int i,j,temp,f[10],fp[10];
int no,p[15],part[15],pno,pr[15],prmem[15];
//Input partition size
printf("\n*******************************************");
printf("\n IMPLEMENTATION OF WORST-FIT ALGORITHM");
printf("\n*******************************************");
printf("\n Enter the number of partitions");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
p[i]=i;
printf("Enter the memory for partition %d:\t",i);
scanf("%d",&part[i]);
}
//Arrange partitions in descending order
for(i=1;i<=no;i++)
{
for(j=1;j<=i;j++)
{
if(part[j]<part[i])
{
temp=part[i];
part[i]=part[j];
part[j]=temp;
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
printf("\nFree memory");
for(i=1;i<=no;i++)
{
printf("\n partition %d: \t %d",p[i],part[i]);
}
Free memory
Partition 1 : 700
Partition 2 : 600
Partition 3 : 500
Enter the number of process3
-----------------------------------------------------------------------
------------------------------------------------------------------------
1 1 600
2 2 400
3 3 200