Fibonacci Number in C using Recursive Function

A recursive function is a function that calls itself during its execution.

#include<stdio.h>

int fibonacci(unsigned long n){

	if(n <=1 )
		return n;
	else

		return fibonacci(n-1) + fibonacci(n-2);

}

int main(){
	int n;
	printf("enter positive integer: ");

	scanf("%i", &n);
	int x = fibonacci(n);

	printf("fib(%i) = %i", n, x);
	return 0;

}

 

output:

Fibonacci Program

what r u trying to show.................

the above source code will print the nth number in fibonacci series....

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.