Untitled

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

#define max 20


int main()
{
    int np,nb,p[max],b[max],frag[max],i,j,temp,lowest;
    static int bf[max],ff[max];
    printf("Enter the no of blocks:\n");
    scanf("%d",&nb);
    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 no of processes:\n");
    scanf("%d",&np);
    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<=np;i++)
    {
        for(j=1;j<=nb;j++)
        {
            if(bf[j]!=1)
            {
                temp=b[j]-p[i];
            }
            if(temp>=0)
            {
                if(lowest>temp)
                {
                    ff[i]=j;
                    lowest=temp;
                }
            }
        }
        frag[i]=lowest;
        bf[ff[i]]=1;
        lowest=10000;
    }
    printf("\nProcessno\tProcess size\tBlockno\tBlock size\tFragment");
    for(i=1;i<=np && ff[i]!=0;i++)
    {
        printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,p[i],ff[i],b[ff[i]],frag[i]);
    }
    return 0;
}
Editor is loading...
Leave a Comment