MVT ALGORITHM
#include<stdio.h>
#include<conio.h>
#include<process.h>
#define MAX 10
void main()
{
int ma,ch,ps,psi[MAX]={0},sa[MAX],ea[MAX],hsa[MAX],hea[MAX],hcount=0,pcount=0;
int i=0,j=0,k;
clrscr();
printf("\nEnter total memory available (in MB)");
scnaf("%d",&ma);
while(1)
{
printf("\nThe options available are\n1.Entering prg\n2.deleting a prg\n3.exit\nEnter ur choice");
scanf("%d",&ch);
switch(ch)
{
case 3:
printf("\n\nThe memory available is %d MB",ma);
exit(0);
case 1:
printf("\nEnter size of program(in MB)");
scanf("%d",&ps);
psi[i]=ps;
if(ps<=ma)
{
pcount++;
if(!i)
{
sa[i]=0;
ea[i]=ps-1;
}
else
{
sa[i]=ea[i-1]+1;
ea[i]=sa[i]+ps-1;
}
i++;
ma-=ps;
}
else
{
printf("\nMemory not sufficient for ur prg");
}
printf("\n\nprg details");
printf("\n\nprg num\tmem loc");
printf("\n---------\t-------");
for(k=0;k<pcount;k++)
printf("\n%d\t\t%d-%d",k+1,sa[k],ea[k]);
if(hcount)
{
printf("\nHoles details");
printf("\nhole num\tmem loc");
printf("\n---------\t------");
for(k=0;k<hcount;k++)
printf("\n\n%d\t\t%d-%d",k+1,sa[k],hea[k]);
}
break;
case 2:
printf("\nEnter the prg no u want to delete");
scanf("%d",&ch);
if(ch>pcount)
{
printf("\n no such prg");
break;
}
printf("\n A hole is created b/t mem loc %d & %d",sa[ch-1],ea[ch-1]);
hcount++;
hsa[j]=sa[ch-1];
hea[j]=ea[ch-1];
sa[ch-1]=ea[ch-1]=-1;
j++;
break;
default:
printf("\ninvalid choice");
break;
}
}
}
I've made it much more understandable the above following code
ReplyDeleteMVT:-
#include
#include
#define max 20
struct memorychunk
{
int size_of_process;
} process[max];
int main()
{
int memorysize,no_of_processes,i,external_fragmentation[10],total_external_fragmentation=0,remaining_size;
printf("enter the size of the total memory available:");
scanf("%d",&memorysize);
printf("\nenter the number of processes that are ready to occupy the main memory:");
scanf("%d",&no_of_processes);
for(i=0;i<no_of_processes;i++)
{
printf("\nenter the size of the process%d being entered :",i);
scanf("%d",&process[i].size_of_process);
if(process[i].size_of_process<=memorysize)
{
printf("\nmemory allocated");
external_fragmentation[i]=(memorysize-process[i].size_of_process);
printf("\nremaining size for the next process is %d",external_fragmentation[i]);
remaining_size=memorysize-process[i].size_of_process;
memorysize=remaining_size;
total_external_fragmentation=(total_external_fragmentation+external_fragmentation[i]);
}
else
{
printf("memory not allocated for process %d due to overbound of size",i);
}
}
printf("\nthe total external fragmentation of the total memory is%d",remaining_size);
return 0;
}
I've made it much more understandable the above following code
ReplyDeleteMVT:-
#include
#include
#define max 20
struct memorychunk
{
int size_of_process;
} process[max];
int main()
{
int memorysize,no_of_processes,i,external_fragmentation[10],total_external_fragmentation=0,remaining_size;
printf("enter the size of the total memory available:");
scanf("%d",&memorysize);
printf("\nenter the number of processes that are ready to occupy the main memory:");
scanf("%d",&no_of_processes);
for(i=0;i<no_of_processes;i++)
{
printf("\nenter the size of the process%d being entered :",i);
scanf("%d",&process[i].size_of_process);
if(process[i].size_of_process<=memorysize)
{
printf("\nmemory allocated");
external_fragmentation[i]=(memorysize-process[i].size_of_process);
printf("\nremaining size for the next process is %d",external_fragmentation[i]);
remaining_size=memorysize-process[i].size_of_process;
memorysize=remaining_size;
total_external_fragmentation=(total_external_fragmentation+external_fragmentation[i]);
}
else
{
printf("memory not allocated for process %d due to overbound of size",i);
}
}
printf("\nthe total external fragmentation of the total memory is%d",remaining_size);
return 0;
}