Reply to comment

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

Reply

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.