blanker algorithm | C code

#include<stdio.h> #include<conio.h> void main() { int k=0,output[10],d=0,t=0,ins[5],i,avail[5],allocated[10][5],need[10][5],MAX[10][5],pno,P[10],j,rz, count=0; printf("Enter the number of processes : "); scanf("%d", &pno); printf("\nEnter the number of resources : "); scanf("%d", &rz); printf("\nEnter the max instances of resources\n"); for(i=0;i<rz;i++) { avail[i]=0; printf("%c= ",(i+65)); scanf("%d",&ins[i]); } printf("\nEnter the allocation \n "); printf("\n"); for(i=0;i <pno;i++) { P[i]=i; printf("P[%d] \n",P[i]); for(j=0;j<rz;j++) { printf("%c: ",j+65); scanf("%d",&allocated[i][j]); avail[j]+=allocated[i][j]; } printf("\n"); } printf("\nEnter the MAX \n "); for(i=0;i<rz;i++) { avail[i]=ins[i]-avail[i]; } printf("\n"); for(i=0;i <pno;i++) { printf("P[%d] \n",i); for(j=0;j<rz;j++) { printf("%c: ",(j+65)); scanf("%d", &MAX[i][j]); } printf("\n"); } printf("\n"); A: d=-1; for(i=0;i <pno;i++) { count=0; t=P[i]; for(j=0;j<rz;j++) { need[t][j] = MAX[t][j]-allocated[t][j]; if(need[t][j]<=avail[j]) count++; } if(count==rz) { output[k++]=P[i]; for(j=0;j<rz;j++) avail[j]+=allocated[t][j]; } else P[++d]=P[i]; } if(d!=-1) { pno=d+1; goto A; } printf("\t Sequence is:- <"); for(i=0;i<k;i++) printf("P[%d] ",output[i]); printf(">"); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.