Advertisement
Shishu

first fit program in c

Dec 5th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. ...http://world-of-c-programming.blogspot.com/2012/11/first-fit-memory-management-algorithm.html
  2.  
  3.  
  4. #include<stdio.h>
  5. #include<conio.h>
  6. #define max 25
  7.  
  8. void main()
  9. {
  10.     int frag[max],b[max],f[max],i,j,nb,nf,temp;
  11.     static int bf[max],ff[max];
  12.  
  13.     printf("\n\tMemory Management Scheme - First Fit");
  14.     printf("\nEnter the number of blocks:");
  15.     scanf("%d",&nb);
  16.     printf("Enter the number of files:");
  17.     scanf("%d",&nf);
  18.     printf("\nEnter the size of the blocks:-\n");
  19.     for(i=1; i<=nb; i++)
  20.     {
  21.         printf("Block %d:",i);
  22.         scanf("%d",&b[i]);
  23.     }
  24.     printf("Enter the size of the files :-\n");
  25.     for(i=1; i<=nf; i++)
  26.     {
  27.         printf("File %d:",i);
  28.         scanf("%d",&f[i]);
  29.     }
  30.  
  31.     for(i=1; i<=nf; i++)
  32.     {
  33.         for(j=1; j<=nb; j++)
  34.         {
  35.             if(bf[j]!=1)
  36.             {
  37.                 temp=b[j]-f[i];
  38.                 if(temp>=0)
  39.                 {
  40.                     ff[i]=j;
  41.                     break;
  42.                 }
  43.             }
  44.         }
  45.         frag[i]=temp;
  46.         bf[ff[i]]=1;
  47.     }
  48.     printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
  49.     for(i=1; i<=nf; i++)
  50.         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]);
  51.     getch();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement