0% found this document useful (0 votes)
16 views3 pages

Program 6 A

The document presents a C program that simulates the worst fit technique for contiguous memory allocation. It prompts the user to enter the number of memory blocks and files, followed by their respective sizes. The program then allocates files to blocks based on the worst fit strategy and displays the allocation results along with any memory fragments.

Uploaded by

pranavshekarc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Program 6 A

The document presents a C program that simulates the worst fit technique for contiguous memory allocation. It prompts the user to enter the number of memory blocks and files, followed by their respective sizes. The program then allocates files to blocks based on the worst fit strategy and displays the allocation results along with any memory fragments.

Uploaded by

pranavshekarc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program-6

Develop a C program to simulate the following contiguous memory allocation

Techniques

a) Worst fit

#include <stdio.h>

int main()

int fragments[10], blocks[10], files[10];

int m, n, number_of_blocks, number_of_files, temp, top = 0;

static int block_arr[10], file_arr[10];

printf("\nEnter the Total Number of Blocks:\t");

scanf("%d", &number_of_blocks);

printf("Enter the Total Number of Files:\t");

scanf("%d", &number_of_files);

printf("\nEnter the Size of the Blocks:\n");

for(m = 0; m < number_of_blocks; m++)

printf("Block No.[%d]:\t", m + 1);

scanf("%d", &blocks[m]);

}
printf("Enter the Size of the Files:\n");

for(m = 0; m < number_of_files; m++)

printf("File No.[%d]:\t", m + 1);

scanf("%d", &files[m]);

for(m = 0; m < number_of_files; m++)

for(n = 0; n < number_of_blocks; n++)

if(block_arr[n] != 1)

temp = blocks[n] - files[m];

if(temp >= 0)

if(top < temp)

file_arr[m] = n;

top = temp;

fragments[m] = top;

block_arr[file_arr[m]] = 1;
top = 0;

printf("\nFile Number\tFile Size\tBlock Number\tBlock Size\tFragment");

for(m = 0; m < number_of_files; m++)

printf("\n%d\t%d\t%d\t%d\t%d", m + 1, files[m], file_arr[m] + 1, blocks[file_arr[m]],


fragments[m]);

printf("\n");

return 0;

You might also like