Wednesday, 10 April 2013

C Program to print fibonacci series



A Fibonacci sequence is defined as Follows
The first and second terms in the sequence are 0 and 1 subsequent terms are found by adding the preceding two terms in the sequence. Write a C program to generate the first n terms of the sequence


c program to print fibonacci series
Program:

#include <stdio.h>

#include <conio.h>

void main()

{

 int a,b,c,i,n;

 clrscr();

 a=0;

 b=1;

 printf("\n enter n for how many times generate series");

 scanf("%d",&n);

 printf("\n FIBONACCI SERIES\n");

 printf("\t%d\t%d",a,b);

for(i=0;i<n;i++)

{

     c=a+b;

     a=b;

     b=c;

     printf("\t%d",c);

 }

 getch();

}

No comments: