一个过河问题的程序
这是我写的,不知道哪有错误,运行的时候好像是个死循环#include <math.h>
#include <stdio.h>
main()
{
int time=0,k;
double p,q;
struct river
{int m;
int w;
};
struct river side;
struct river1
{int a;
int b;
};
struct river1 boat;
side.m=3;
side.w=3;
boat.a=1;
boat.b=1;
k=1;
while(side.m!=0&&side.w!=0)
{
p=pow(-1,k)*boat.a+side.m;
q=pow(-1,k)*boat.b+side.w;
if(p>=q)
{
side.m=p;
side.w=q;
printf(" %d",k);
k++;
}
else
{
if(time<3)
{
boat.a=time;
boat.b=2-time;
time++;
}
else time=0;
}
}
getch();
}