Hanochsunil / lab

0 stars 0 forks source link

BEST FIT #7

Open Hanochsunil opened 5 months ago

Hanochsunil commented 5 months ago

include

struct pro{ int size,allocation; }pro[10]; int main(){ int nb,np,best,i,j,block[10]; printf("Enter the no of memory blocks"); scanf("%d",&nb); printf("Enter the memory blocks"); for(i=0;i<nb;i++) { scanf("%d",&block[i]); } printf("Enter the no of process"); scanf("%d",&np); printf("Enter the process"); for(i=0;i<np;i++) { scanf("%d",&pro[i].size); pro[i].allocation=0; } //allocations method for(i=0;i<np;i++) { best=-1; for(j=0;j<nb;j++) { if(pro[i].size<=block[j]) { if(best==-1) { best=j; } else if(block[j]<block[best]) { best=j; } } } if(best!=-1) { pro[i].allocation=block[best]; block[best]=block[best]-pro[i].size; } } printf("\nSi.no Process Allocated"); for(i=0;i<np;i++) { if(pro[i].allocation!=0) { printf("\n%d %d %d",i+1,pro[i].size,pro[i].allocation); }else{ printf("\n%d %d Not allocated",i+1,pro[i].size); } } }