Generate fibonacci series upto nth term - C

Q. WAP to print fibonacci series in C programming   2018 Group B, Q.no.6, 5 Marks - PU BIT
Soln : Fibonacci series ==> It is a series of numbers where the current number is the sum of previous two terms. For Example: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ... , (n-1th + n-2th).
Code goes like this : 

/* Fibonacci Series in C Programming */
#include<stdio.h>
int main()
{
    int a=0,b=1,c,i,num;
    printf("Enter a number: ");
    scanf("%d",&num);
        for(i=1;i<=num;i++)
    {
    c=a+b;
    printf(" %d ",a);
    a=b;
    b=c;
    }
    return 0;
}
Output : 

I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment