我如何找到分配的第一个地址(firstad)和最后一个地址(lastad)? 并输出以下错误消息:输入值为零和负,大于最大分区的请求以及没有可用分区的合法请求。
这是我到目前为止所拥有的:
#include<stdio.h>
void main()
{
int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999;
int lastad[10], firstad[10];
static int block_arr[20],pro_arr[20];
printf("\n\t\t\tMemory Management Scheme - Best Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block no.[%d]:",i);
scanf("%d",&b[i]);
}
printf("\nEnter the number of processes:");
scanf("%d",&np);
printf("\nEnter the size of the processes :-\n");
for(i=1;i<=np;i++)
{
printf("Process no.[%d]:",i);
scanf("%d",&p[i]);
}
for(i=1;i<=np;i++)
{
for(j=1;j<=nb;j++)
{
b[i]=0;
if(block_arr[j]!=1)
{
temp=b[j]-p[i];
if(b[j]>=p[i])
{
firstad[i] = p[i];
lastad[i] = b[j]+p[i]-1;
}
if(temp>=0)
if(lowest>temp)
{
pro_arr[i]=j;
lowest=temp;
}
}
}
fragment[i]=lowest;
block_arr[pro_arr[i]]=1;
lowest=10000;
}
printf("\nBlock_no\tBlock_size\tProcess_no\tProcess_size\tFragment"
"\tFirst_Ad \tLast_Ad");
for(i=1;i<=np && pro_arr[i]!=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d \t\t%d\t\t%d",pro_arr[i],b[pro_arr[i]],i,p[i],fragment[i],firstad[i],lastad[i]);
}