All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Friday, 19 September 2014

PROGRAM FOR MFT

#include<iostream>
using namespace std;
int main()
{
int m,os,p,s,p1;
int ps,i,f1=0,fra1;
cout<<"Enter the Memory Size: ";
cin>>m;
cout<<"Enter Memory given to OS: ";
cin>>os;
m-=os;
cout<<"Enter the no of Partitions: ";
cin>>p;
s=m/p;
cout<<"Each Partition size is: "<<s;
cout<<"\nEnter the no of Processes: ";
cin>>p1;
for(i=0;i<p1;i++)
{

if(s>m)
{
cout<<"\nNo Partition Available for Process"<<i+1<<endl;
}
else
{

cout<<"\nEnter the Process"<<i+1<<" Size=";
cin>>ps;
if(ps<=s)
{
cout<<"\nProcess Allocated to memory";
m-=s;
fra1=s-ps;
cout<<"\nInternal Fragmentation:"<<fra1<<endl;
f1+=fra1;
}
else
{
cout<<"\nProcess Not Allocated to Memory\n";
}
}
}
cout<<"\nThe Total fragmentation is: "<<f1;
return 0;

}

No comments:

Post a Comment