C Program to Display Fibonacci Series

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Program for Fibbonacci series
// 0    1    1    2    3   5    8   13  21 .......n
#include<stdio.h>
#include<conio.h>
int main()
{
     int n,a,b,c,i;
     a=0;
     b=1;
     system("cls");
     printf("Enter the limit");
     scanf("%d",&n);
     if(n==1)  // if limit is 1
       printf("%d",a);
    else   
     if(n==2)  // if limit is 2
       printf("%d %d ",a,b);
     else
     if(n>2)  // if limit is 3    
     {
        printf("%d %d ",a,b);
            i=1;
         while(i<=n-2) 
         {
            c=a+b; 
            printf(" %d ",c); 
              a=b;
              b=c;
              i++;
         }   
               

     }



}

 

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *