program for MVT algoritham using c-languge


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;
}
}
}





program for LINKED algoritham using c-languge


LINKED ALGORITHM
#include<stdio.h>
#include<conio.h>
typedef struct file
{
 char name[10];
 int start,size,block[10];
}fil;


main()
{
 fil f[10];
int i,j,n;
clrscr();
printf("Enter number of files: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
 printf("\nEnter the filename: ");
scanf("%s",f[i].name);
printf("Enter the starting block of the file: ");
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
printf("Enter the size of the file: ");
scanf("%d",&f[i].size);
for(j=1;j<f[i].size;j++)
{
 printf("Enter the next block number:");
 scanf("%d",&f[i].block[j]);
}
}
printf("File \t Start \t Size \t Blocks \n");
for(i=0;i<n;i++)
{
 printf("%s\t%d\t%d\t",f[i].name,f[i].start,f[i].size);
 for(j=0;j<f[i].size;j++)
 printf("%d-->",f[i].block[j]);
printf("-1 \n");
}
printf("\n");                               
getch();
}