Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can you write an algorithm to find fibonacci series?

user-image
Question added by feysel debela
Date Posted: 2016/12/05
Riki  Mondal
by Riki Mondal , Full Stack Debeloper , National Institute of Technology Durgapur

#include<stdio.h> int fib(int n) {    if (n <= 1)       return n;    return fib(n-1) + fib(n-2); }   int main () {   int n = 9;   printf("%d", fib(n));   getchar();   return 0; }

Pradeep  Sharma
by Pradeep Sharma , Assistant Professor , Assam down town Unniversity

Fibonacci(n)

begin:

declare f0, f1

set f0=0  and f1=1

display f0, f1

for 1: n

fib = f0 + f1

f0 = f1

f1 = fib

display fib

end

/* Fibonacci Series c language */ #include<stdio.h>   int main() { int n, first = 0, second = 1, next, c;   printf("Enter the number of terms\\n"); scanf("%d",&n);   printf("First %d terms of Fibonacci series are :-\\n",n);   for ( c = 0 ; c < n ; c++ ) { if ( c <= 1 ) next = c; else { next = first + second; first = second; second = next; } printf("%d\\n",next); }   return 0; }

 

More Questions Like This