Follow Us

LightBlog

Breaking

Saturday, February 4, 2017

Write a program to generate the Fibonacci series using c language.

Write a program to generate the Fibonacci series using c language.

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


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

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

    for(k=2;k<r;k++)
  {
         temp=i+j;
         i=temp;
         j=temp;
         printf(" %ld",j);
    }
  
    return 0;
}

Sample output:
Enter the number range: 15
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

No comments:

Post a Comment