Generation of Fibonacci Series -C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
    int a[200];int i,n,t1=1,t2=1,t3,x,y;//clrscr();
    a[1]=1;a[2]=1;
    printf("Enter the no of terms:");
    scanf("%d",&n);
    if(n<=0)
        printf("Error..!");
    else if(n==1)
        printf("The fibonacci series:\n1");
    else if(n==2)
        printf("The fibonacci series:\n1,1");
    else
        printf("The fibonacci series:\n1,1");
        for(i=3;i<=n;i++)
            {
                t3=t1+t2;
                t1=t2;
                t2=t3;
                printf(",%d",t2);
                a[i]=t3;
            }
    printf(",...\n");
    //getch();
}

Output:
nn@linuxmint ~ $ gcc c4.c
nn@linuxmint ~ $ ./a.out
Enter the no of terms:5
The fibonacci series:
1,1,2,3,5,...
nn@linuxmint ~ $

1 comment:

  1. Enroll in our Best Mern Stack Course In South Delhi and dive deep into the intricacies of full-stack web development using the MERN technology. Build a solid foundation for a successful career in web development.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...