Skip to content

Commit 0351e6f

Browse files
authored
FIRST FIT
1 parent 47dd20a commit 0351e6f

File tree

1 file changed

+48
-0
lines changed
  • Dynamic Partitioning Placement Algorithms

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//FIRST-FIT
2+
3+
#include<stdio.h>
4+
#include<conio.h>
5+
#define max 25
6+
void main()
7+
{
8+
int frag[max],b[max],f[max],i,j,nb,nf,temp;
9+
static int bf[max],ff[max];
10+
printf("\n\tMemory Management Scheme - First Fit");
11+
printf("\nEnter the number of blocks:");
12+
scanf("%d",&nb);
13+
printf("Enter the number of files:");
14+
scanf("%d",&nf);
15+
printf("\nEnter the size of the blocks:-\n");
16+
for(i=1;i<=nb;i++)
17+
{
18+
printf("Block %d:",i);
19+
scanf("%d",&b[i]);
20+
}
21+
printf("Enter the size of the files :-\n");
22+
for(i=1;i<=nf;i++)
23+
{
24+
printf("File %d:",i);
25+
scanf("%d",&f[i]);
26+
}
27+
for(i=1;i<=nf;i++)
28+
{
29+
for(j=1;j<=nb;j++)
30+
{
31+
if(bf[j]!=1)
32+
{
33+
temp=b[j]-f[i];
34+
if(temp>=0)
35+
{
36+
ff[i]=j;
37+
break;
38+
}
39+
}
40+
}
41+
frag[i]=temp;
42+
bf[ff[i]]=1;
43+
}
44+
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
45+
for(i=1;i<=nf;i++)
46+
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
47+
getch();
48+
}

0 commit comments

Comments
 (0)