/* This is the tenth lab of Lab EE107
The purpose of this lab for finding out the Fibonacci numbers via
a variable length array..
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 2nd, 2024.
*/

#include <stdio.h>

// Function to generate Fibonacci numbers
void generateFibonacci_EU(int n_EU, unsigned long long fibo_EU[]) {
    fibo_EU[0] = 0; // First Fibonacci number
    fibo_EU[1] = 1; // Second Fibonacci number

    // Generate subsequent Fibonacci numbers
    for (int i_EU = 2; i_EU < n_EU; i_EU++) {
        fibo_EU[i_EU] = fibo_EU[i_EU - 1] + fibo_EU[i_EU - 2];
    }
}

int main() {
    int n_EU;

    // Input the number of Fibonacci numbers to generate
    printf("Enter the number of Fibonacci numbers to generate: ");
    scanf("%d", &n_EU);

    // Check if the input is valid
    if (n_EU <= 0) {
        printf("Please enter a positive integer.\n");
        return 1; // Exit with error code
    }

    // Define a variable-length array to store Fibonacci numbers
    unsigned long long fiboSequence_EU[n_EU];

    // Generate Fibonacci numbers
    generateFibonacci_EU(n_EU, fiboSequence_EU);

    // Display the Fibonacci sequence
    printf("Fibonacci Sequence:\n");
    for (int i_EU = 0; i_EU < n_EU; i_EU++) {
        printf("%llu ", fiboSequence_EU[i_EU]);
    }
    printf("\n");

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: