The fibonacci series goes like this:
0, 1, 1, 2, 3, 5, 8, 13, 21
Program below reads user's desired fibonacci position and output the fibonacci value.
/*
title: fibonacciSeries
coder: aeriqusyairi
date: Jan21 2012
*/
#include<stdio.h>
long fibonacci(long n);
int main(void){
long result;
long number;
printf("Enter an integer: ");
scanf("%ld", &number);
result = fibonacci(number);
printf("Fibonacci(%ld) = %ld\n", number, result);
system("pause");
return 0;
}
long fibonacci(long n){
if(n == 0 || n == 1)
return n;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}
No comments:
Post a Comment