Fibonacci Series C - C Program to show Fibonacci Series



 c program to show fibonacci series

Learn C - C tutorial - c program to show fibonacci series - C examples - C programs

C Program to show Fibonacci Series

  • The Fibonacci sequence is a set of numbers that starts with a 1 or 0, followed by a 1, and continues based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers.
  • If the Fibonacci sequence is denoted F (n), where n is the first term in the sequence, the following equation obtains for n = 0, where the first two terms are defined as 0 and 1 by convention:
    • F (0) = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34….

Sample Code

#include <stdio.h>
#include <stdlib.h>
int Fibonacci(int x)
{
    if (x < 2)
    {
        return x;
    }
    return (Fibonacci (x - 1) + Fibonacci (x - 2));
}
int main(void)
{
    int number=9;
    printf( "Positive integer:");
    if (number < 0)
        printf( "That is not a positive integer.\n");
    else
        printf("%d \nFibonacci is: %d\n", number, Fibonacci(number));
    return 0;
}

Output

Positive integer:9 
Fibonacci is: 34


View More Quick Examples


Related Searches to C Program to show Fibonacci Series