Advertisement
Tusohian

MFT (Need to Fix Errors)

Oct 24th, 2018
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void main()
  4. {
  5.     int mem, blk, pr, info[100], blkn=0, i, n, ifrag=0, efrag;
  6.  
  7.     printf(" Enter Memory Size: ");
  8.     scanf("%d", &mem);
  9.  
  10.     printf(" Enter Block Size: ");
  11.     scanf("%d", &blk);
  12.  
  13.     blkn=mem/blk;
  14.     efrag=mem-blkn*blk;
  15.  
  16.     printf("\n Available Block Number: %d \n", blkn);
  17.  
  18.     printf(" Enter The Number of Process: ");
  19.     scanf("%d", &n);
  20.  
  21.  
  22.     for (i=1; i<=n; i++)
  23.     {
  24.         printf(" Enter the information of P%d: ", i);
  25.         scanf("%d", &info[i]);
  26.     }
  27.  
  28.     printf("\nProcess  \t  Mem Req  \t  Allowed   \t  Int. Frag\n");
  29.  
  30.     pr=0;
  31.     if(blkn!=0)
  32.     {
  33.         for(i=1; i<=n && pr<=blkn; i++)
  34.         {
  35.             printf("\n %d\t\t%d", i+1, info[i]);
  36.             if(info[i]>blk)
  37.             {
  38.                 printf("\t\tNo\t\t---");
  39.             }
  40.             else
  41.             {
  42.                 int temp=blk-info[i];
  43.                 printf("\t\tYes\t%d", temp);
  44.                 ifrag=ifrag+temp;
  45.                 pr++;
  46.             }
  47.  
  48.  
  49.         }
  50.  
  51.         if(i<n)
  52.         {
  53.             printf("Memory is full");
  54.         }
  55.  
  56.         printf("\nTotal Internal Fragmentation: %d", ifrag);
  57.         printf("\nTotal External Fragmentation: %d", efrag);
  58.  
  59.  
  60.  
  61.     }
  62.  
  63.     else printf("There is not available any block");
  64.  
  65.  
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement