Shishu

worst fir program in c

Dec 5th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #define max 25
  4.  
  5. void main()
  6. {
  7.  int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
  8.  static int bf[max],ff[max];
  9.  clrscr();
  10.  
  11.  printf("\n\tMemory Management Scheme - Worst Fit");
  12.  printf("\nEnter the number of blocks:");
  13.  scanf("%d",&nb);
  14.  printf("Enter the number of files:");
  15.  scanf("%d",&nf);
  16.  printf("\nEnter the size of the blocks:-\n");
  17.  for(i=1;i<=nb;i++) {printf("Block %d:",i);scanf("%d",&b[i]);}
  18.  printf("Enter the size of the files :-\n");
  19.  for(i=1;i<=nf;i++) {printf("File %d:",i);scanf("%d",&f[i]);}
  20.  
  21.  for(i=1;i<=nf;i++)
  22.  {
  23.   for(j=1;j<=nb;j++)
  24.   {
  25.    if(bf[j]!=1)    //if bf[j] is not allocated
  26.    {
  27.     temp=b[j]-f[i];
  28.     if(temp>=0)
  29.     if(highest<temp)
  30.     {
  31.      ff[i]=j;
  32.      highest=temp;
  33.     }
  34.    }
  35.   }
  36.   frag[i]=highest;
  37.   bf[ff[i]]=1;
  38.   highest=0;
  39.  }
  40.  printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
  41.  for(i=1;i<=nf;i++)
  42.  printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
  43.  getch();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment