当前位置:网站首页>Three methods for solving Fibonacci sequence feibonacci (seeking rabbit) - program design

Three methods for solving Fibonacci sequence feibonacci (seeking rabbit) - program design

2022-06-23 01:45:00 kalada82

1,1,2,3,5,8,13,,,,,

This is it. feibonaci Count

F1=1,n=1

f2=1,n=2

fn=fn-1+fn-2,n=3

To put it simply , Programming ;

data type ( It is important to understand the principle , It is very helpful to understand why it is written in this form )

( operation , data ) Definition of variables ( Determination of needs )

( Various ) The determination of boundaries ( The starting point ,, End )

Determination of process ( Split of steps , Determine the basic operation )

Key conditions ( The border ) The determination of ( Branch ?)

// loop - Reuse variables

// Basics 3 Variable

#include<stdio.h>

int main()

{

       int f1=1,f2=1,f3;

       int i;

       printf("%l2\n%l2d\n",f1,f2);

       for(i=1;i<=38;i++)

       {

              f3=f1+f2;

              printf("%ld\n",f3);

              f1=f2;

              f2=f3;

       }

       return 0;

}

//for Cycle optimization ,2 Variable version

 #include<stdio.h>

 int main()

 {

      int f1=1,f2=1;

      int i;

      for(i=1;i<=20;i++)

      {

             printf("%l2d %l2d",f1,f2);

             if(i%2==0)printf("\n");

             f1=f1+f2;

             f2=f2+f1;

        }

        return 0;

 }

// Find one-dimensional array of rabbits

#include<stdio.h>

int main()

{

       int i;

       int f[20]={

              1,1

       };

       for(i=2;i<20;i++)

              f[i]=f[i-2]+f[i-1];

       for(i=0;i<20;i++)

              {

                     if(i%5==0)printf("\n");// Format control

                     printf("%12d",f[i]);

              }

       printf("\n");

       return 0;

}

// Find one-dimensional array of rabbits

#include<stdio.h>

int main()

{

       int i;

       int f[20]={

              1,1

       };

       for(i=2;i<20;i++)

              f[i]=f[i-2]+f[i-1];

       for(i=0;i<20;i++)

              {

                     if(i%5==0)printf("\n");// Format control

                     printf("%12d",f[i]);

              }

       printf("\n");

       return 0;

}

原网站

版权声明
本文为[kalada82]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202220512374344.html