Untitled

 avatar
unknown
plain_text
a year ago
1.2 kB
3
Indexable
#include <stdio.h>

int main() {
    int bsize[10], psize[10], bno, pno, flags[10], allocation[10], i, j;

    for(i = 0; i < 10; i++) {
        flags[i] = 0;
        allocation[i] = -1;
    }

    printf("Enter the number of memory blocks: ");
    scanf("%d", &bno);

    printf("Enter the size of each memory block: \n");
    for(i = 0; i < bno; i++) {
        scanf("%d", &bsize[i]);
    }
    printf("Enter the number of processes: ");
    scanf("%d", &pno);
    printf("Enter the size of each process: \n");
    for(i = 0; i < pno; i++) {
        scanf("%d", &psize[i]);
    }
    for(i = 0; i < pno; i++) {
        for(j = 0; j < bno; j++) {
            if(flags[j] == 0 && bsize[j] >= psize[i]) {
                allocation[i] = j;
                flags[j] = 1;
                break;
            }
        }
    }
    printf("\nProcess No.\tProcess Size\tBlock no.\n");
    for(i = 0; i < pno; i++) {
        printf("%d\t\t%d\t\t", i+1, psize[i]);
        if(allocation[i] != -1) {
            printf("%d\n", allocation[i]+1);
        } else {
            printf("Not Allocated\n");
        }
    }

    return 0;
}
Editor is loading...
Leave a Comment