Advertisement
derazanother

Untitled

Feb 7th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include<stdio.h>
  2. #define max 25
  3. //best
  4. void main()
  5. {
  6.     int bsize[max], psize[max], bno, pno, flags[max], allocation[max],parray[max],fragm[max], i, j, temp,lowest=9999;
  7.  
  8.     for(i = 0; i < max; i++)
  9.     {
  10.         flags[i] = 0;
  11.         allocation[i] = -1;
  12.         fragm[i] = 0;
  13.     }
  14.    
  15.     printf("Enter no. of blocks: ");
  16.     scanf("%d", &bno);
  17.    
  18.     printf("\nEnter size of each block:-\n");
  19.     for(i = 0; i < bno; i++){
  20.         printf("Block %d: ",i);
  21.         scanf("%d", &bsize[i]);
  22.     }
  23.    
  24.     printf("\nEnter no. of processes: ");
  25.     scanf("%d", &pno);
  26.    
  27.     printf("\nEnter size of each process:-\n");
  28.     for(i = 0; i < pno; i++){
  29.         printf("Process %d: ",i);
  30.         scanf("%d", &psize[i]);
  31.     }
  32.    
  33.     for(i = 0; i < pno; i++){        
  34.         for(j = 0; j < bno; j++){
  35.            
  36.             //Detect the size of block is larger than the size of process.
  37.             if(allocation[j]!=1)
  38.             {
  39.                 //Calculate the size between block and process
  40.                 temp=bsize[j]-psize[i];
  41.                
  42.                 if(temp>=0){
  43.                     if(lowest>temp)
  44.                     {
  45.                         //Assign the current block
  46.                         parray[i]=j;
  47.                         lowest=temp;
  48.                     }
  49.                 }
  50.             }
  51.         }
  52.         //Allocate the current process to block
  53.             allocation[parray[i]] = 1;
  54.        
  55.         flags[parray[i]] = 1;
  56.        
  57.         //Calculating Fragment
  58.         fragm[i]= temp;
  59.         lowest=9999;
  60.     }
  61.    
  62.     //display allocation details
  63.     printf("%d %d %d",temp,lowest,fragm[i]);
  64.     printf("\nBlock no.\tBsize\t\tprocess no.\t\tPsize\t\\Fragment");
  65.     for(i = 0; i < bno; i++)
  66.     {
  67.         printf("\n%d\t\t%d\t\t", i, bsize[i]);
  68.         if(flags[i] == 1)
  69.             printf("%d\t\t\t%d\t%d",allocation[i],psize[allocation[i]],fragm[i]);
  70.         else
  71.             printf("Not allocated");
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement