Print a Fibonacci series


 

#include<stdio.h>

#include<conio.h>

int main( )

{

   int n, a=1, b=1, temp;

   

   printf("Enter the number");

   scanf("%d",&n);


  printf("Fibonacci series is %d %d ", a,b);


  while(a+b<=n)

    {

       temp=a;

       a=b;

       b=a+temp;

       printf("%d ",b);

    }

return 0;

}


Output:-

Enter the number6

Fibonacci series is 1 1 2 3 5 



Comments

Popular posts from this blog

Check whether the no entered is Palindrome or not

Calculate Factorial of a given no with help of Recursion

Find max. and min. element in the integer array