費氏數列

 avatar
user_3763047219
c_cpp
2 years ago
438 B
2
Indexable
Never
#define _CRT_SCURE_NO_WARNINGS
#include <iostream>

void getFib(int N);

void getFib(int N) {
    int a[100];
    a[0] = 0;
    a[1] = 1;
    for (int i = 2; i <= N; i++) {
        a[i] = a[i - 2] + a[i - 1];
    }
    for (int i = 0 ; i < N-1; i++) {
        printf("%d ", a[i]);
    }
    printf("%d", a[N-1]);
}


#include <stdio.h>
int main() {
    int N;
    scanf("%d", &N);
    getFib(N);

    return 0;
}