Search C Program

Loading...

Fibonacci by Recursion

/* Fibonacci by Recursion */

#include<stdio.h>
int fib(int);

int main()
{
 printf("Type any value : ");
 printf("\nNth value: %d",fib(getche()-'0'));
 return 0;
}

int fib(int n)
{
 if(n<=1)
  return n;
 return(fib(n-1)+fib(n-2));
}

6 comments:

  1. In function 'fib':
    Line 13: error: 'x' undeclared (first use in this function)
    Line 13: error: (Each undeclared identifier is reported only once
    Line 13: error: for each function it appears in.

    ReplyDelete
  2. Line 7: error: `getche' undeclared (first use this function)

    ReplyDelete
  3. The program is compiled successfully but as we run the program its returning the same number we asked for series

    ReplyDelete