⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 l3.txt

📁 计算机操作系统银行家算法月分个月毫分个毫 吨个一月毫有那边年不
💻 TXT
字号:
#include<stdio.h>
#define M 6
#define N 4
void main()
{
 int p[N][M];
 int a,i,j,k,m,flag=1;
 char b;
 while(flag)
{
 system("CLS");
 printf("\nthere are %d process in system!\n",N);
 printf("\nplease input the maxresource!\n");
 for(i=0;i<N;i++)
   {
     printf("\ninput the maxresource of p%d:",i);
      scanf("%d",&p[i][1]);
   }
 printf("\nplease input the allocation!\n");
 for(i=0;i<N;i++)
  {
   printf("\ninput the allocation of p%d:",i);
    scanf("%d",&p[i][2]);
   }
 printf("\nplease input the available of resources:");
 scanf("%d",&a);
 for(i=0;i<N;i++)
     {
     p[i][3]=p[i][1]-p[i][2];
     p[i][5]=0;
     p[i][4]=0;
     }
printf("---------------------------------------------------------------\n");
printf("| ProcessId |     Max    | Allocation  |    Need   | Available|\n");
printf("---------------------------------------------------------------\n");
for(i=0;i<N;i++)
   {
      printf("|    P%d     |  %6d    |  %6d     |  %6d   | %6d   |\n",i,p[i][1],p[i][2],p[i][3],p[i][4]);
      printf("---------------------------------------------------------------\n");
    }
printf("\nnow process will requst resources!");
getch();
printf("\nthe order of request successfully process is:");
for(j=0;j<N;j++)
{
 i=0;
 while(i<N)
 {
  if(!p[i][5])
   {
    if(p[i][3]<=a)
    {
    printf(" P%d",i);
    p[i][4]=a;
    a=a+p[i][2];
    p[i][5]=1;
    }
   }
  i++;
  }
}
if(p[0][5]==0&&p[1][5]==0&&p[2][5]==0&&p[3][5]==0)
   printf("\nthere is not enough resources to distribution!\nno process can request successfully!\n");
printf("\nthe table of request and distribution is:\n");
printf("---------------------------------------------------------------\n");
printf("| ProcessId |     Max    | Allocation  |    Need   |Available |\n");
printf("---------------------------------------------------------------\n");
for(i=0;i<N;i++)
   {
      printf("|    P%d     |  %6d    |  %6d     |  %6d   | %6d   |\n",i,p[i][1],p[i][2],p[i][3],p[i][4]);
      printf("---------------------------------------------------------------\n");
    }
printf("please input '1' to continue or '0' to exit!\n");
scanf("%d",&flag);
}
exit();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -