Search Your C Program

Sunday 12 February 2012

Program to print the n terms of fibonacci series.

#include<stdio.h>
#include<conio.h>
void main()
{
                int a,b,c,i,n;
                a=0;
                b=1;
                clrscr();
                printf("\n Enter the number of terms");
                scanf("%d", &n);
                if(n == 1)
                          printf("\n  %d  ",a);
                else if(n>=2)
                {
                                  printf("\n  %d  \t  %d ",a,b);
                                  for(i=3;i<=n;i++)
                                  {
                                                    c=a+b;
                                                    printf("\t  %d",c);
                                                    a=b;
                                                    b=c;
                                   }
                 }
             
                 getch();
 }

No comments:

Post a Comment