# Finding Fibonacci With Both Simple Logic and Mathematical Formula in C

Join the DZone community and get the full member experience.

Join For Freeto find fibonacci sequence, mathematically there're several ways like recursif function and using the golder ratio or x^2 - x - 1 = 0 equation.

above is a recursif function which can be calculated like this

according to the formula, we have initial values for f(0) = 0, f(1) =1

so for n > 1 , we have smth like this:

f(2) = f(2-1) + f(2-2) = f(1) + f(0) = 1 + 0 = 1 ans so on....for the next n so it will finally form the sequence 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

**
but mosth people dont like recurif.
**

we have another options to do that

1. use just a simple logic (see the code)

2. or use the formula

fibonacci numbers can also be found by this formula

**then we only need to form the formula into code**

float x1 = ( 1 + sqrt(5) ) / 2;

that's it.

further fibonacci + faktorial + prime code

```
1. simple logic
int fibonaci(int n){
int i,next,a=0,b=1;
for(i=0;i
```

Opinions expressed by DZone contributors are their own.

Comments