Facebook
From Memory, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 171
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #define max 25
  4. void main()
  5. {
  6. int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
  7. static int bf[max],ff[max];
  8. clrscr();
  9. printf("\n\tMemory Management Scheme - Worst Fit");
  10. printf("\nEnter the number of blocks:");
  11. scanf("%d",&nb;);
  12. printf("Enter the number of files:");
  13. scanf("%d",&nf;);
  14. printf("\nEnter the size of the blocks:-\n");
  15. for(i=1;i<=nb;i++)
  16. {
  17. printf("Block %d:",i);
  18. scanf("%d",&b[i]);
  19. }
  20. printf("Enter the size of the files :-\n");
  21. for(i=1;i<=nf;i++)
  22. {
  23. printf("File %d:",i);
  24. scanf("%d",&f[i]);
  25. }
  26. for(i=1;i<=nf;i++)
  27. {
  28. for(j=1;j<=nb;j++)
  29. {
  30. if(bf[j]!=1) //if bf[j] is not allocated
  31. {
  32. temp=b[j]-f[i];
  33. if(temp>=0)
  34. if(highest<temp)
  35. {
  36. ff[i]=j;
  37. highest=temp;
  38. }
  39. }
  40. }
  41. frag[i]=highest;
  42. bf[ff[i]]=1;
  43. highest=0;
  44. }
  45. printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
  46. for(i=1;i<=nf;i++)
  47. 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]);
  48. getch();
  49. }
  50. #include<stdio.h>
  51. #include<conio.h>
  52. #define max 25
  53. void main()
  54. {
  55. int frag[max],b[max],f[max],i,j,nb,nf,temp;
  56. static int bf[max],ff[max];
  57. clrscr();
  58. printf("\n\tMemory Management Scheme - First Fit");
  59. printf("\nEnter the number of blocks:");
  60. scanf("%d",&nb;);
  61. printf("Enter the number of files:");
  62. scanf("%d",&nf;);
  63. printf("\nEnter the size of the blocks:-\n");
  64. for(i=1;i<=nb;i++)
  65. {
  66. printf("Block %d:",i);
  67. scanf("%d",&b[i]);
  68. }
  69. printf("Enter the size of the files :-\n");
  70. for(i=1;i<=nf;i++)
  71. {
  72. printf("File %d:",i);
  73. scanf("%d",&f[i]);
  74. }
  75. for(i=1;i<=nf;i++)
  76. {
  77. for(j=1;j<=nb;j++)
  78. {
  79. if(bf[j]!=1)
  80. {
  81. temp=b[j]-f[i];
  82. if(temp>=0)
  83. {
  84. ff[i]=j;
  85. break;
  86. }
  87. }
  88. }
  89. frag[i]=temp;
  90. bf[ff[i]]=1;
  91. }
  92. printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
  93. for(i=1;i<=nf;i++)
  94. 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]);
  95. getch();
  96. }
  97. #include<stdio.h>
  98. #include<conio.h>
  99. #define max 25
  100. void main()
  101. {
  102. int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
  103. static int bf[max],ff[max];
  104. clrscr();
  105. printf("\nEnter the number of blocks:");
  106. scanf("%d",&nb;);
  107. printf("Enter the number of files:");
  108. scanf("%d",&nf;);
  109. printf("\nEnter the size of the blocks:-\n");
  110. for(i=1;i<=nb;i++)
  111. {
  112. printf("Block %d:",i);
  113. scanf("%d",&b[i]);
  114. }
  115. printf("Enter the size of the files :-\n");
  116. for(i=1;i<=nf;i++)
  117. {
  118. printf("File %d:",i);
  119. scanf("%d",&f[i]);
  120. }
  121. for(i=1;i<=nf;i++)
  122. {
  123. for(j=1;j<=nb;j++)
  124. {
  125. if(bf[j]!=1)
  126. {
  127. temp=b[j]-f[i];
  128. if(temp>=0)
  129. if(lowest>temp)
  130. {
  131. ff[i]=j;
  132. lowest=temp;
  133. }
  134. }
  135. }
  136. frag[i]=lowest;
  137. bf[ff[i]]=1;
  138. lowest=10000;
  139. }
  140. printf("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment");
  141. for(i=1;i<=nf && ff[i]!=0;i++)
  142. 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]);
  143. getch();
  144. }