OneCompiler

banker

1628

#include<stdio.h>

int process ,resources;
int allocation[20][20];
int max[20][20];
int need[20][20];
int available[20];

void calculateneed()
{
for (int i=0;i<process;i++)
{
for (int j=0; j<resources ; j++)
{
need[i][j]=max[i][j]-allocation[i][j];
}
}
}

void accept(){
printf("Enter the number of process : ");
scanf("%d",&process);
printf("enter the number of resources :");
scanf("%d",&resources);

for(int i=0;i<process ; i++)
{
for(int j=0;j< resources; j++)
{
printf("Enter the allocation for process P%d :",i);
scanf("%d",&allocation[i][j]);
}

}

printf("\n\n enter the max matrix now \n ");
for(int i=0;i<process ; i++)
{
for (int j=0; j< resources; j++)
{
printf("enter the Max for process P%d :",i);
scanf("%d",&max[i][j]);
}
}

for(int i=0;i<resources;i++)
{
printf("Enter the resource for available ");
scanf("%d",&available[i]);
}

}

void display( int allocation[20][20], int process , int resources){

printf(" ");
for (int i=’A’; i< ’A’ +resources ;i++)
{
printf(" %c ",i);
}

printf("\n");

for (int i=0;i<process ; i++)
{
printf("P%d ",i);
for (int j=0; j<resources ; j++)
{
printf(" %d ",allocation[i][j]);
}
printf("\n");
}

printf("\n");
}

void showavailable(){
for (int i=0; i<resources; i++){
printf(" %d ",available[i]);
}
}

int main()
{
accept();
printf("Allocations:\n ");
display(allocation , process , resources);
printf("Max:\n");
display(max, process, resources);
printf("Available \n");
showavailable();
calculateneed();
printf("\nneed:\n");
display(need, process,resources);

}