标题:一个Fibonacci算法,不知道到底是哪里出错了,要怎么改啊
取消只看楼主
bid2938692
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2009-9-23
结帖率:76.92%
已结贴  问题点数:6 回复次数:1 
一个Fibonacci算法,不知道到底是哪里出错了,要怎么改啊
#include "stdio.h"
#define true 1
#define false 0
typedef int keytype;
typedef int datatype;
typedef struct{   
    keytype key;
    datatype other;
}rectype;
int fibonacci(n)
int n;
{    if(n==0)
        return(0);
    else
        if(n==1)
            return(1);
        else
            return (fibonacci(n-1)+fibonacci(n-2));
}
int fibosrch(rectype R[],keytype k,int n)
    {    int i,p,q,s,t,flag1,flag2;
        i=fibonacci(n-1);
        p=fibonacci(n-2);
        q=fibonacci(n-3);
        s=n+1-(i+p);
        if(k>R[i].key)
            i=i+s;
        flag1=false;
        while((i)&&(!flag1))
        {    if(R[i].key==k)
                flag2=1;
            else
                if(R[i].key<k)
                    flag2=2;
                else
                    if(R[i].key>k)
                        flag2=3;
            switch(flag2)
            {case 1:flag1=true;
                    break;
             case 2:if(q==0)
                    i=0;
                    else
                    {i=i-q;
                     t=p;
                     p=q;
                     q=t-q;
                    }
                    break;
             case 3:if(p==1)
                        i=0;
                    else
                    {    i=i+q;
                        p=p-q;
                        q=q-p;
                    }
                    break;
             default;
            }
        }
        return (i);
    }
int main()
{    int a,i,k;
    rectype R[15];
    scanf("%d",&k);
    for(i=1;i<=15;i++)
        scanf("%d",R[i].key);
    a=fibosrch(R,k,15);
    printf("%d",a);
    return 0;
}
代码是按照课本原样输入的,不知道要怎么改了~~~~到底是哪里出错呢
搜索更多相关主题的帖子: Fibonacci 算法 
2010-05-31 23:36
bid2938692
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2009-9-23
得分:0 
楼上的那个是什么编译器捏??
2010-06-01 21:34



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




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

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