用Fibonacci数列表示任意正整数

本文探讨如何使用Fibonacci数列来表示任意正整数,例如45可以分解为34加上8再加上3,这种方法揭示了数列与整数之间的有趣联系。
摘要由CSDN通过智能技术生成

如:

45=34+8+3

#include<stdio.h>
#include<math.h>
#include<malloc.h>
int table[30];
typedef struct node
{
    int res[30];
    int len;
    int data;
    struct node *next;
}node;
void init_table()
{
    int i;
    table[1]=1;
    table[2]=1;
    for(i=3;i<30;i++)
    {
        table[i]=table[i-1]+table[i-2];
    }
}
void compute_res(node *p)
{
    int i,n;
    n=p->data;
    p->len=0;
        for(i=30-1;i>=0;i--)
       {
        if(table[i]<=n&&n!=0)
        {
            p->res[p->len++]=table[i];
            n=n-table[i];
        }
       }
};
void init_node(node **head,node **tail,node *p)
{
    if(*head==NULL)
    {
        *head=p;
        *tail=p;
    }
    else
    {
        (*tail)->next=p;
        *tail=p;
    }
};
void print(struct node *h)
{
    w
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值