Preview:
void printFibonacci(int n) {
    FILE* file = fopen("/var/www/vusers/TIFACyournameone/Fib.txt", "w");
    if (file == NULL) {
        printf("Failed to open file\n");
        return;
    }

    int fib1 = 0;
    int fib2 = 1;
    int fib;
    fprintf(file, "%d\n%d\n", fib1, fib2);

    for (int i = 2; i < n; i++) {
        fib = fib1 + fib2;
        fprintf(file, "%d\n", fib);
        fib1 = fib2;
        fib2 = fib;
    }

    fclose(file);
    printf("Fibonacci series written to Fib.txt\n");
}

int main() {
    int n;
    printf("Enter the number of Fibonacci series terms: ");
    scanf("%d", &n);
    printFibonacci(n);
    return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter