Tuesday, August 5, 2014

Fibonacci series

Write a program to calculate fibonacci series.

SOLUTION:

 /*
 * Fibonacci series
 * Written by Shaeed Khan. 
 * Date: 05 Aug 2014
 * Version- 1.0 
 * Language: C
 */

#include < stdio.h >      
#include < stdlib.h > 

void main()
{
 int n;
 printf("Enter the number range:");
 scanf("%d",&n);
 fibo(n);
}

int fibo(int n)
{
 int i=0,j=1,k=2,r,f;
 printf("%d %d ", i,j);
 while( k < n )
 {
  f = i + j;
  i = j;
  j = f;
  printf( " %d", j );
  k++;
 }
} 

No comments:

Post a Comment