The document presents a C program that implements the First Fit memory allocation algorithm. It allows users to input memory block sizes and process sizes, then allocates memory to processes based on the First Fit strategy. The program outputs the allocation results and the remaining memory in each block.
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 ratings0% found this document useful (0 votes)
9 views3 pages
11A First Fit Program:: Sprno:9223
The document presents a C program that implements the First Fit memory allocation algorithm. It allows users to input memory block sizes and process sizes, then allocates memory to processes based on the First Fit strategy. The program outputs the allocation results and the remaining memory in each block.
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
You are on page 1/ 3
Sprno:9223
11A FIRST FIT
PROGRAM: #include <stdio.h> #define MAX_BLOCKS 20 #define MAX_PROCESSES 20 void firstFit(int blockSize[], int blocks, int processSize[], int processes) { int allocation[MAX_PROCESSES]; // Initialize allocation array for (int i = 0; i < processes; i++) { allocation[i] = -1; } // Allocate using First Fit for (int i = 0; i < processes; i++) { for (int j = 0; j < blocks; j++) { if (blockSize[j] >= processSize[i]) { allocation[i] = j; blockSize[j] -= processSize[i]; break; } } } // Display the results printf("\nProcess No.\tProcess Size\tAllocated Block\n"); for (int i = 0; i < processes; i++) { printf("P%d\t\t%d\t\t", i + 1, processSize[i]); if (allocation[i] != -1) printf("Block %d\n", allocation[i] + 1); else printf("Not Allocated\n"); } Sprno:9223
// Show remaining block sizes
printf("\nRemaining Memory in Blocks:\n"); for (int i = 0; i < blocks; i++) { printf("Block %d: %d\n", i + 1, blockSize[i]); } } int main() { int blockSize[MAX_BLOCKS], processSize[MAX_PROCESSES]; int blocks, processes; printf("Enter number of memory blocks: "); scanf("%d", &blocks); printf("Enter sizes of %d memory blocks:\n", blocks); for (int i = 0; i < blocks; i++) { scanf("%d", &blockSize[i]); } printf("Enter number of processes: "); scanf("%d", &processes); printf("Enter sizes of %d processes:\n", processes); for (int i = 0; i < processes; i++) { scanf("%d", &processSize[i]); } firstFit(blockSize, blocks, processSize, processes); return 0; } OUTPUT: Enter number of memory blocks: 4 Enter sizes of 4 memory blocks: 200 300 100 400 Enter number of processes: 3 Sprno:9223