急急~!~!高手来帮个忙~!
怎么能让当你输入Y循环执行,输入N退出,代码改咋弄!~!谢谢了啊~#include <stdio.h>
#include <string.h>
void main()
{
int print1(int need);
int print2(int allocation);
int available[3]={10,5,7};
int max[5][3]={7,5,3,3,2,2,9,0,2,2,2,2,4,3,3};
int allocation[5][3]={0};
int need[5][3]={7,5,3,3,2,2,9,0,2,2,2,2,4,3,3};
int i,j,k,m,n,p;
char t;
printf("------------------------------------------\n系统可用的资源数为:\n");
printf("资源0:%d 资源1:%d 资源2:%d",available[0] ,available[1] ,available[2]);
printf("\n------------------------------------------\n各进程还需要的资源量:\n");
for(i=0;i<5;i++)
{
printf("进程%d: ",i);
for(j=0;j<3;j++)
printf("资源%d:%d ",j,need[i][j]);
printf("\n");
}
printf("\n------------------------------------------\n各进程已得到的资源量:\n");
for(i=0;i<5;i++)
{
printf("进程%d: ",i);
for(j=0;j<3;j++)
printf("资源%d:%d ",j,allocation[i][j]);
printf("\n");
}
printf("如想继续银行家算法演示,请按‘y’键继续或‘n’键退出:");
scanf("%c",&t);
while(t=='y')
{
printf("请输入您要申请资源的进程号:");
scanf("%d",&k);
if(k>=0&&k<5)
{
printf("请输入进程%d申请的资源数:",k);
scanf("%d%d%d",&m,&n,&p);
printf("资源0的申请数:%d",m);
printf("资源1的申请数:%d",n);
printf("资源2的申请数:%d",p);
}
need[k][0]=need[k][0]-m;
need[k][1]=need[k][1]-n;
need[k][2]=need[k][2]-p;
allocation[k][0]=allocation[k][0]+m;
allocation[k][1]=allocation[k][1]+n;
allocation[k][2]=allocation[k][2]+p;
printf("\n------------------------------------------\n各进程还需要的资源量:\n");
for(i=0;i<5;i++)
{
printf("进程%d: ",i);
for(j=0;j<3;j++)
printf("资源%d:%d ",j,need[i][j]);
printf("\n");
}
printf("\n------------------------------------------\n各进程已得到的资源量:\n");
for(i=0;i<5;i++)
{
printf("进程%d: ",i);
for(j=0;j<3;j++)
printf("资源%d:%d ",j,allocation[i][j]);
printf("\n");
}
printf("如想继续银行家算法演示,请按‘y’键继续或‘n’键退出:");
scanf("%c",&t);
}
}
怎么能让当你输入Y循环执行,输入N退出,代码改咋弄!~!谢谢了啊~!