Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
961 B
1
Indexable
Never
#include<stdio.h>

#define max 20

int main()
{
    int np,nb,p[max],b[max],i,j;
    printf("Enter the no of blocks:\n");
    scanf("%d",&nb);
    printf("Enter the no of processes:\n");
    scanf("%d",&np);
    printf("Enter the size of each block:\n");
    for(i=1;i<=nb;i++)
    {
        printf("Block%d:",i);
        scanf("%d",&b[i]);
    }
    printf("Enter the size of each process:\n");
    for(i=1;i<=np;i++)
    {
            printf("process%d:",i);
            scanf("%d",&p[i]);
    }
    
    for(i=1;i<=nb;i++)
    {
        for(j=1;j<=np;j++)
        {
            if(p[j]<=b[i])
            {
                printf("the process %d allocated to block %d\n",j,b[i]);
                p[j]=10000;
                break;
            }
        }
    }
    for(j=1;j<=np;j++)
    {
        if(p[j]!=10000)
        {
            printf("the process %d is not allocated\n",j);
        }
    }
    return 0;
}
Leave a Comment