derazanother

Untitled

Feb 7th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. #include<stdio.h>
  2. #define max 25
  3. //ff
  4. void main()
  5. {
  6.     int bsize[max], psize[max], bno, pno, flags[max], allocation[max],fragm[max], i, j;
  7.  
  8.     for(i = 0; i < max; i++)
  9.     {
  10.         flags[i] = 0;
  11.         allocation[i] = -1;
  12.         fragm[i] = 1;
  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.     //Loop for all process
  34.     for(i = 0; i < pno; i++){  
  35.         for(j = 0; j < bno; j++){
  36.            
  37.             //Detect the size of block is larger than the size of process.  
  38.             if(flags[j] == 0 && bsize[j] >= psize[i])
  39.             {
  40.                
  41.                 //Allocate the process to block
  42.                 allocation[j] = i;
  43.                
  44.                 flags[j] = 1;
  45.                
  46.                 //Calculating Fragment
  47.                 fragm[i] = fragm[i]+(bsize[i]-psize[i]);
  48.                 break;
  49.             }
  50.         }
  51.     }
  52.    
  53.     //display allocation details
  54.  
  55.    
  56.     printf("\nBlock no.\tBsize\t\tprocess no.\t\tPsize\t\\Fragment");
  57.     for(i = 0; i < bno; i++)
  58.     {
  59.         printf("\n%d\t\t%d\t\t", i, bsize[i]);
  60.         if(flags[i] == 1){
  61.            
  62.             printf("%d\t\t\t%d\t%d",allocation[i],psize[allocation[i]],fragm[i]);
  63.            
  64.            
  65.            
  66.  
  67.         }
  68.         else
  69.             printf("Not allocated");
  70.     }
  71.    
  72. }
Add Comment
Please, Sign In to add comment