• 0

problem with bankers algorithm


Question

#include<stdio.h>

#include<conio.h>

int main()

{

int a[10][10],b[10][10],n[10][10],i,j,x,y,succ,done;

int z[10],flag[10]={0},r,p;

printf("enter the number of resources you want ti have ");

scanf("%d",&r);

printf("\n enter the reqest matrix \n ");

for(x=1;x<=r;x++)

{

for(y=1;y<=r;y++)

{

scanf("%d",&b[x][y]);

}

}

printf("\n enter the allocation matrix");

for(x=1;x<=r;x++)

{

for(y=1;y<=r;y++)

{

scanf("%d",&a[x][y]);

}

}

for(x=1;x<=r;x++)

{

for(y=1;y<=r;y++)

{

n[x][y]=b[x][y]-a[x][y];

printf(" %d",n[x][y]);

}

printf("\n");

}

printf("\n Enter the resource vector\n");

for(x=1;x<=r;x++)

{

scanf("%d",&z[x]);

}

done=r;

for(x=1;x<=r && done>=0;x++)

{

succ=1;

for(y=1;y<=r;y++)

{

if(z[y]>=n[x][y] && succ==1)

{

flag[x]=1;

if(y==r)

{

for(i=1;i<=r;i++)

{

z=z+a[x];

}

flag[x]=1;

done--;

succ=1;

x=1;

}

}

else

{

flag[x]=0;

succ=0;

if(y==r)

{

done--;

break;

}

}

}

}

for(x=1;x<=r;x++)

{

if(flag[x]==1)

{

printf("\nprocess [%d] in safe state",x);

}

else if(flag[x]==0)

{

printf("\nprocess [%d] unsafe",x);

}

}

getch();

}

or

formatted code

bankers.txt

Edited by pradyot
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.