0% found this document useful (0 votes)
9 views2 pages

First Fit

The document is a C program that implements a memory allocation algorithm. It prompts the user to input the number of memory blocks and processes, then allocates memory blocks to processes based on their sizes. Finally, it outputs the allocation results, indicating which processes were allocated memory and which were not.

Uploaded by

12113139
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)
9 views2 pages

First Fit

The document is a C program that implements a memory allocation algorithm. It prompts the user to input the number of memory blocks and processes, then allocates memory blocks to processes based on their sizes. Finally, it outputs the allocation results, indicating which processes were allocated memory and which were not.

Uploaded by

12113139
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

#include <stdio.

h>

int main()

int blockSize[10], processSize[10], blockCount, processCount, allocation[10] = {-1}, i, j;

printf("Enter the number of memory blocks: ");

scanf("%d", &blockCount);

printf("Enter the size of each memory block:\n");

for (i = 0; i < blockCount; i++)

scanf("%d", &blockSize[i]);

printf("\nEnter the number of processes: ");

scanf("%d", &processCount);

printf("Enter the size of each process:\n");

for (i = 0; i < processCount; i++)

scanf("%d", &processSize[i]);

for (i = 0; i < processCount; i++)

for (j = 0; j < blockCount; j++)

if (blockSize[j] >= processSize[i])

allocation[i] = j;

blockSize[j] -= processSize[i];

break;

}
}

printf("\nProcess No.\tProcess Size\tBlock no.\n");

for (i = 0; i < processCount; i++)

printf(" %d\t\t %d\t\t", i + 1, processSize[i]);

if (allocation[i] != -1)

printf(" %d\n", allocation[i] + 1);

else

printf(" Not Allocated\n");

return 0;

You might also like