Q:

Write C program to generate nth fibonacci term using recursion

0

Write C program to generate nth fibonacci term using recursion

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include<stdio.h>
 
int fibonacci(int n)
{
    if((n==1)||(n==0))
    {
        return(n);
    }
    else
    {
        return(fibonacci(n-1)+fibonacci(n-2));
    }
}
 
int main()
{
    int n,i=0;
    printf("Input the number of terms for Fibonacci Series:");
    scanf("%d",&n);
    printf("\nFibonnaci Series is as follows\n");
    while(i<n)
    {
        printf("%d ",fibonacci(i));
        i++;
    }
 
    return 0;
}

Result:

Input the number of terms for Fibonacci Series:10

Fibonnaci Series is as follows

0 1 1 2 3 5 8 13 21 34 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write C program to find factorial of a number usin... >>
<< Write C program to find sum of array elements usin...