Sunday, May 5, 2013

Find fibonacci series to the given number


#include<stdio.h>
int main()
{
    int k=2,r;
    long int i=0l,j=1,f;

    printf("Enter the number range:");
    scanf("%d",&r);

    printf("Fibonacci series is: %ld %ld",i,j);

    while(k<r){
         f=i+j;
         i=j;
         j=f;
         printf(" %ld",j);
          k++;
    }
 
    return 0;
}


output

Enter the number range: 10
Fibonacci series is: 0 1 1 2 3 5 8 13 21 34

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More