Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Bankers algorithm in c

# Bankers algorithm in c

Ratings: (0)|Views: 2,078|Likes:

### Availability:

See more
See less

05/23/2013

pdf

text

original

#include<stdio.h>#include<conio.h>void main(){int aloc[10][10],need[10][10],max[10][10],av[10],rv[10];int nr=0,np=0,complete[10];int i=0,j=0,sum=0,ctr=0;clrscr();//GETTING REQUIRED DATA....printf("\nEnter num of process: ");scanf("%d",&np);printf("\nEnetr num of resources: ");scanf("%d",&nr);if(np==0  nr==0){printf("\nwrong input...\nplease enter correct value");getch();return;}printf("\nEnter resource vector: ");for(i=0;i<nr;i++){scanf("%d",&rv[i]);}printf("\nEnter max claim matrix: ");for(i=0;i<np;i++){for(j=0;j<nr;j++){scanf("%d",&max[i][j]);}}printf("\nEnter allocation matrix: ");for(i=0;i<np;i++){for(j=0;j<nr;j++){scanf("%d",&aloc[i][j]);}}//find need matrix...for(i=0;i<np;i++){for(j=0;j<nr;j++){need[i][j] = 0;need[i][j] = max[i][j] - aloc[i][j] ;}}//find avilable resources..for(i=0;i<nr;i++){av[i]=0;

for(j=0;j<np;j++){sum = sum + aloc[j][i] ;}av[i] = rv[i] - sum ;sum=0;}//initialising complete vector...for(i=0;i<np;i++){complete[i]=0;}//DISPLAY THE INPUT WITH INITIAL SITUATION...printf("\nALOC_MATRIX\tMAX_CLAIM\tNEED");for(i=0;i<np;i++){printf("\n");for(j=0;j<nr;j++){printf("%d ",aloc[i][j]);}printf("\t\t ");for(j=0;j<nr;j++){printf("%d ",max[i][j]);}printf("\t ");for(j=0;j<nr;j++){printf("%d ",need[i][j]);}}printf("\nResource vector: ");for(i=0;i<nr;i++){printf("%d ",rv[i]);}printf("\nAvailable resources: ");for(i=0;i<nr;i++){printf("%d ",av[i]);}//FINDING SAFE SEQUENCE...again:for(i=0;i<np;i++){if(complete[i]==1){continue;}else{