Advertisement
_Black_Panther_

Untitled

Mar 19th, 2021
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <iostream>
  3. #include<math.h>
  4. using namespace std;
  5. #define MAX 50
  6. int main(){
  7.  
  8.     int page[MAX],i,n,f,ps,off,pno,ProcessSize, internalFrag;
  9.     int choice=0;
  10.  
  11.     //printf("\nEnter the no of  peges in memory: ");
  12.     //scanf("%d",&n);
  13.  
  14.     printf("\nEnter page size: ");
  15.     scanf("%d",&ps);
  16.  
  17.     printf("\nEnter process size: ");
  18.     scanf("%d",&ProcessSize);
  19.  
  20.  
  21.     n = ceil(ProcessSize / (ps*1.0)) ;
  22.  
  23.     //cout << "n: " << n << endl;
  24.     internalFrag = ps - (ProcessSize % ps);
  25.     cout << "Internal fragmentation: \n" << internalFrag << endl;
  26.     printf("\nEnter no of frames: ");
  27.     scanf("%d",&f);
  28.  
  29.     for(i=0;i<n;i++)
  30.         page[i]=-1;
  31.  
  32.     printf("\nEnter the page table\n");
  33.     printf("(Enter frame no as -1 if that page is not present in any frame)\n\n");
  34.     printf("\npageno\tframeno\n-------\t-------");
  35.  
  36.     for(i=0;i<n;i++){
  37.         printf("\n\n%d\t\t",i);
  38.         scanf("%d",&page[i]);
  39.     }
  40.  
  41.     do{
  42.         printf("\n\nEnter the logical address(i.e,page no & offset):");
  43.         scanf("%d%d",&pno,&off);
  44.         if(page[pno]==-1)
  45.         printf("\n\nThe required page is not available in any of frames");
  46.         else
  47.         printf("\n\nPhysical address(i.e,frame no & offset):%d,%d",page[pno],off);
  48.        
  49.         printf("\nDo you want to continue(1/0)?:");
  50.         scanf("%d",&choice);
  51.     }while(choice==1);
  52.  
  53.  
  54.     return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement