Hanochsunil / lab

0 stars 0 forks source link

WORST #8

Open Hanochsunil opened 2 months ago

Hanochsunil commented 2 months ago

include

struct pro{ int size,allocation; }pro[10]; int main(){ int nb,np,worst,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++) { worst=-1; for(j=0;j<nb;j++) { if(pro[i].size<=block[j]) { if(worst==-1) { worst=j; } else if(block[j]>block[worst]) { worst=j; } } } if(worst!=-1) { pro[i].allocation=block[worst]; block[worst]=block[worst]-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); } } }