what is fibonacci series in c

10 months ago 44
Nature

The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. In C, the Fibonacci series can be implemented using iteration or recursion. Here's an example of how to display the Fibonacci sequence in C:

c

#include <stdio.h>

int main() {
    int n, first = 0, second = 1, next, c;
    
    printf("Enter the number of terms: ");
    scanf("%d", &n);
    
    printf("Fibonacci Series: ");
    
    for (c = 0; c < n; c++) {
        if (c <= 1)
            next = c;
        else {
            next = first + second;
            first = second;
            second = next;
        }
        printf("%d, ", next);
    }
    
    return 0;
}

This code will prompt the user to enter the number of terms and then display the Fibonacci series up to the specified number of terms