Pages

Best Fit Implementation

              /*PROGRAM TO IMPLEMENT THE CONCEPTS OF BEST-FIT*/

   #include<stdio.h>
   #include<conio.h>
   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<n;i++)
     scanf("%d",&ps[i]);
     printf("\nEnter the process-size:");
     scanf("%d",&prs);
     for(i=0;i<n;i++)
     d[i]=ps[i]-prs;
     printf("\nDifference:");
     for(i=0;i<n;i++)
     printf("\t%d",d[i]);
     for(i=0;i<n;i++)
     if(d[i]>=0)
      {
       min=d[i];
       l=i;
       break;
      }
       for(i=l;i<n;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*/

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

If you like this please Link Back to this article...



0 comments:

Post a Comment