Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
806 B
1
Indexable
Never
#include <stdlib.h>
#include <stdio.h>

void Fibonacci(int n, int bin[]) {
    int first = 0, second = 1, next;

    bin[0] = 0;
    bin[1] = 1;

    for (int i = 0; i < n; i++) {
        next = first + second;
        bin[i + 2] = next;
        first = second;
        second = next;
    }
}

void change(int n, int num[], int bin[]) {
    for (int i = 0; i < n; i++) {
        num[i] = bin[i] * bin[i + 1];
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int *bin = (int *)malloc((n + 2) * sizeof(int)); // To store the Fibonacci sequence
    int *num = (int *)malloc(n * sizeof(int));       // To store intermediate results

    Fibonacci(n, bin);
    change(n, num, bin);

    printf("%d", num[n - 1]);

    free(bin);
    free(num);

    return 0;
}
Leave a Comment