Pages

Monday, January 9, 2012

C Programming to find nth term of Fibonacci series

/* to find nth term of Fibonacci's series */
#include<stdio.h>
#include<stdlib.h>
int fib(int);
int main()
{
    int n;
    printf("Enter the value of n: ");
    scanf("%d",&n);
    printf("%dth term of Fibonacci's series is %d\n",n,fib(n));
    system("pause");
    return 0;
}
int fib(int n)
{
  if (n < 2)
    return n;
  else
    return fib(n-1) + fib(n-2);
}

No comments:

Post a Comment