Displaying Source Code(s)
|
|
BEST FIT - CPU scheduling algorithm
--------------------------------------------------------------------------------
Description : This program gives program details of Fitting a
job with given size into the Avail Memory Block.
//BEST FIT
//R.NADARAJAN ME/CSE
#include<stdio.h>
#include<conio.h>
void main()
{
int padd[10],msize[10],madd[10],psize[10],rpsize[10];
int nom,n,i,j,k,t_madd[10],t_msize[10];
clrscr();
printf("\n\n\t\t * * * BEST FIT * * *\n\n");
// Getting input
printf("\nNo. of partitions in Memory: \t");
scanf("%d",&nom);
for(i=0;i<nom;i++)
{
printf("\nAddress of partition:\t");
scanf("%d",&madd[i]);
printf("\nEnter the SIZE :\t");
scanf("%d",&msize[i]);
}
printf("\nProcess SIZE:\t");
scanf("%d",&psize[0]);
printf("\n\nBefore allocation:-\n");
printf("\nADDRESS \tAVAIL. SIZE\t\n");
for(i=0;i<nom;i++)
{
printf("\n%d\t\t%d\n",madd[i],msize[i]);
}
for(k=0;k<nom;k++)
{
for(j=k;j<nom;j++)
{
if(msize[k]>msize[j])
{
t_madd[j]=madd[j];
madd[j]=madd[k];
madd[k]=t_madd[j];
t_msize[j]=msize[j];
msize[j]=msize[k];
msize[k]=t_msize[j];
}
}
}
for(i=0;i<nom;i++)
{
if(psize[0]<=msize[i])
{
printf("\n partition");printf(" %d",madd[i]);printf(" was
filled\n");
madd[i]+=psize[0];
msize[i]-=psize[0];
break;
}
}
//display memory block
printf("\nAfter allocation:-\n\n");
printf("\nADDRESS \tFREE SPACE\t\n");
for(i=0;i<nom;i++)
{
printf("\n%d\t\t%d\n",madd[i],msize[i]);
}
getch();
}
|
|
|