ASP ScriptingJava ScriptingCGI ScriptingHTMLJavaLanguage CERP Education Links

LANGUAGE C

Recursive Function

     Recursion is  the process of defining something in terms of itself, and is sometimes called circular definition. A function is said to be recursive if a statement in the body of the function calls itself. Each recursive function must specify an exit condition for it to terminate, otherwise it will go  on indefinitely.

#include <stdio.h>
main ( )
{
int n;
long int i;
long int fibo(int n);
clrscr ( ) ;
printf("Enter the number n for which \n"); printf("\tfibonacci number desired . "); 
scanf ("%d", &n) ;
i = fibo (n) ;
printf("The %dth fibonacci no. is %ld\n", n, i) ;
}
long int fibo(int m)
{
if (m <= 2)
return ( 1 ) ;
else 
return ( fibo (m - 1 )+ fibo(m - 2));
}

 


Your Ad Here
Not All Of Your Subscribers Use RSS - AWeber Email Marketing
Your Ad Here