pradyot Posted March 18, 2009 Share Posted March 18, 2009 (edited) #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 March 18, 2009 by pradyot Link to comment Share on other sites More sharing options...
0 rson451 Posted March 18, 2009 Share Posted March 18, 2009 Ask a question? Link to comment Share on other sites More sharing options...
0 Bookieass Posted March 19, 2009 Share Posted March 19, 2009 Your attached code and posted code differs........... which one is the right one??? Link to comment Share on other sites More sharing options...
0 +Majesticmerc MVC Posted March 20, 2009 MVC Share Posted March 20, 2009 We might be able to help if you asked a question! Link to comment Share on other sites More sharing options...
Question
pradyot
#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 pradyotLink to comment
Share on other sites
3 answers to this question
Recommended Posts