Find Fibonacci series in C language

 C program to find Fibonacci series

Code:

#include <stdio.h>
int fibo(int num);
int main()
{
    int num;
    int fibonacci;
    printf("Enter any number to find nth fibonacci term: ");
    scanf("%d", &num);
    fibonacci = fibo(num); 
    printf("%d fibonacci term is %d", num, fibonacci);
    return 0;
}
int fibo(int num) 
{
    if(num == 0)      
        return 0;
    else if(num == 1) 
        return 1;
    else 
        return fibo(num-1) + fibo(num-2); 
}


Explanation:

What is Fibonacci series?

  • A series of numbers in which each number (Fibonacci number) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.

  • We are declaring the variables in integer data type
  • We are asking the user to enter a series of number to check whether the number is Fibonacci series are not.
  • Storing the series of number in "num" variable.
  • Using if and else statements to check to check whether the entered number is Fibonacci or not.
Output:




Comments

Popular posts from this blog

Use of Backslash "\n" in C language

COHESION AND COUPLING material

Coding and Testing in software engineering