标题:一个过河问题的程序
只看楼主
wwwjw
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2007-12-28
结帖率:33.33%
 问题点数:0 回复次数:0 
一个过河问题的程序
这是我写的,不知道哪有错误,运行的时候好像是个死循环
#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();
}

1.jpg (83.56 KB)


2.jpg (88.36 KB)


3.jpg (21.11 KB)
搜索更多相关主题的帖子: side boat int struct 
2008-04-21 17:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-210273-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.225563 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved