current position:Home>Find the first 30 numbers of sequence 1 1 2 3 5 8 13 21

Find the first 30 numbers of sequence 1 1 2 3 5 8 13 21

2022-02-02 19:41:04 CSDN Q & A

use for The loop statement outputs the first 30 numbers of the Fibonacci sequence …………………………………………




Refer to the answer 1:

Just loop iteration ,a[0]=a;a[1]=1;a[n] = a[n-1]+a[n-2]
Refer to the following :

#include <iostream>using namespace std;int main(){    int a[30],i;    a[0]=1;    a[1]=1;    cout << "1 1";    for(i=2;i<30;i++)    {        a[i]=a[i-1]+a[i-2];        cout << " " << a[i];    }    return 0;}



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021941023866.html

Random recommended