Fibonnaci series using C upto n terms

 

Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time with something different it is a C logic which will help us to  print the n terms of a given fibonnaci series .

Basically a fibonnaci series is a series in which the sum of the previous two terms gives us the next term 

For e.g:1,1,2,3,5,8,13,....................n

Here goes the code;

#include<stdio.h>
int main()
{
    int b=1,a=0,n;
    printf("Enter the value of n:");
    scanf("%d",&n);
    for (int i = 1; i<n; i++)
    {
        int c=a+b;
        if(c==2)
        {
            printf("1\n");
        }
        printf("%d\n",c);
        a=b;
        b=c;
       
    }
}

Comments

Popular Posts