### What is Fibonacci Series?

The first two Fibonacci numbers are 0 and 1 then next number is addition of previous two numbers.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.....

In mathematics it is defined by recurrence relation.

### Program Code

//C Program for generate Fibonacci series

#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();

}

thanks.......

ReplyDeleteThis comment has been removed by the author.

ReplyDeletethanks

ReplyDeletecan u write this program without taking 0,1 as initial values for a and b variables

ReplyDeleteNo we can't write this code without intiala'n.

Deletevoid main()

Delete{

int i,n;

clrscr();

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

scanf("%d",&n);

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

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

{

cout<<fabo(i)<<" ";

}

getch();

}

fabo(n)

{

if(n==0)

return 0;

if(n==1)

return 1;

else

return fabo(n-1)+fabo(n-2);

}

}

wrong!!!!!

ReplyDeleteu hav printed 8 no's bt v ned only 6 no's???

ReplyDeletefor(i=0;i<n-2;i++)

Deleteif you take

ReplyDeletea=-1

b=1

means u don't need to print a,b

wow thanks its totally right :)

ReplyDeletemind blowing its right

ReplyDeletethanku

ReplyDeletedis is wrong dude ;

ReplyDeletewhen u want 3rd number in the series (dat is 1) you hav to give value of n == 1...

I hope this solves your problem

ReplyDelete#include

#include

void main()

{

int a,b,c,i,n;

a=0;

b=1;

printf("Enter number of terms of the series to be generated:");

scanf("%d",&n);

if(n==1)

{

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

printf("%d",a);

}

else if(n==2)

{

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

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

}

else

{

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

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

{

c=a+b;

a=b;

b=c;

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

}

}

getch();

}

idiot

Deletemaking it complex

/* Fibonacci Series c language */

Delete#include

main()

{

int n,a=0,b=1,c,d;

printf("Enter the number of terms\n");

scanf("%d",&n);

printf("First %d terms of Fibonacci series are :- \n",n);

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

for(d=0;d<n-2;d++)

{

c=a+b;

a=b;

b=c;

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

}

getch();

}

if i enter the no 1 than it will print 0 and 1 both in place of zero

Deletei think it's not proper output

void main()

ReplyDelete{

int a,b,c,i,n;

a=0;

b=1;

printf("Enter number of terms of the series to be generated:");

scanf("%d",&n);

if(n==1)

{

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

printf("%d",a);

}

else if(n==2)

{

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

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

}

else

{

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

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

{

c=a+b;

a=b;

b=c;

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

}

}

getch();

}

OR

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();

}

well, the for loop should be

ReplyDeletefor(i=1;i<=n-2;i++)

good one re, thank you

ReplyDeletethanks..

ReplyDeleteThanks!!!!!!!!!!!

ReplyDeletevoid 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();

}

this is the best.........

ReplyDelete#include

#include

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=1;i<n;i++)

{

c=a+b;

a=b;

b=c;

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

}

getch();

}

hey can u post flow chart for this !!! plzz

ReplyDeletefibonacci series starts with 1 never with 0...

ReplyDeleteI dont know if u right...but what we were taught was starting from zero itself...well maybe u r right....lets see....

DeleteThis comment has been removed by the author.

ReplyDeleteThank you.

ReplyDeletea= -1

ReplyDeleteb=1

sum = a+b

a=b

b=sum

fibonacci series

ReplyDelete#include

#include

void main()

{

int i,n,c,a=0,b=1;

clrscr();

printf("enter the number");

scanf("\n%d\n",&n);

printf("\nFIBONACCI SERIES\n");

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

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

{

c=a+b;

a=b;

b=c;

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

}

getch();

}

thank u..

ReplyDeletecan explain the running of loop?

ReplyDelete//This program will print the fibonacci series by using the printf statement only once...have a close look!!!

ReplyDeletefibonacci series

#include

#include

void main()

{

int i,n,c,a=0,b=1;

clrscr();

printf("enter the number");

scanf("\n%d\n",&n);

printf("\nFIBONACCI SERIES\n");

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

{

printf("%d\n",a);

c=a+b;

a=b;

b=c;

}

getch();

}

hi, u have oversimplified...

Deletethe series is 0,1,1,2,3,5,8... while ur program gives

0,1,2,3,5,8....

so the third term gets missing...

but good attempt....

i think it is best to use

for(couter=1;counter<=N-2;counter++) loop....

:-)

can anyone tell how to write reverse fabonnaci series

ReplyDelete#include

Delete#include

void main()

{

int i,n,c,a=0,b=1;

clrscr();

printf("enter the number");

scanf("\n%d\n",&n);

printf("\nFIBONACCI SERIES\n");

for(i=n;i<n;i--)

{

printf("%d\n",a);

c=a+b;

a=b;

b=c;

}

getch();

}

It's running successfully.......... thanks..

ReplyDeleteThis comment has been removed by the author.

ReplyDelete#include

ReplyDeletemain()

{

int n, first = 0, second = 1, next, c;

printf("Enter the number of terms\n");

scanf("%d",&n);

printf("First %d terms of Fibonacci series are :-\n",n);

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

{

if ( c <= 1 )

next = c;

else

{

next = first + second;

first = second;

second = next;

}

printf("%d\n",next);

}

return 0;

}

Hey Frnz I Have Simple Way To Print it And Hope u Like N try it

ReplyDeleteso let's begin

void main(){

int a,b,i,n;

clrscr();

n=10;

a=0;

b=1;

for(i=1; i<=n; i++){

a=a+b;

b=a-b;

printf("%d ",b);

}

getch();}

the value of 'n' Will Varies as the series wants to maximize

Its simplest n perfect code...!!!

Deletethe program is wrong.. publish the correct coding;;;;

ReplyDeleteu have to give for loop as for(i=2;i<n;i++)

ReplyDeleteremaining thnks are ok................

/* Fibonacci Series c language */

ReplyDelete#include

main()

{

int n,a=0,b=1,c,d;

printf("Enter the number of terms\n");

scanf("%d",&n);

printf("First %d terms of Fibonacci series are :-\n",n);

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

{

if (d<=1)

c=d;

else

{

c=a+b;

a=b;

b=c;

}

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

}

getch();

}

Other way without using "if else"

Delete/* Fibonacci Series c language */

#include

main()

{

int n,a=0,b=1,c,d;

printf("Enter the number of terms\n");

scanf("%d",&n);

printf("First %d terms of Fibonacci series are :- \n",n);

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

for(d=0;d<n-2;d++)

{

c=a+b;

a=b;

b=c;

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

}

getch();

}

All above programs are starting with 0 and 1, what if we want another values say -1 or other integer ? Try this one !

ReplyDelete#include

#include

int main(void)

{

int a,b,c,i,n;

printf("Enter first number: ");

scanf("%d", &a);

printf("\nEnter the second number:");

scanf("%d", &b);

printf("\nHow many times does you want the series:");

scanf("%d",&n);

if(n==1)

{

printf("\nFibonacci series is:\t%d", a);

}

else if(n==2)

{

printf("\nFibonacci series is:\t%d\t%d", a,b);

}

else

{

printf("\nFibonacci series is:\t%d\t%d", a,b);

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

{

c= a+b;

a= b;

b= c;

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

}

}

getch();

}

This comment has been removed by the author.

ReplyDelete#include

ReplyDeletemain()

{

int i,n,a,b;

printf("enter n terms");

scanf("%d",&n);

printf("fibonacci siries\n");

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

{

a=a+b;

b=a+b;

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

}

}

int main()

ReplyDelete{

int a, b, fib, n=10,i;

a=0;b=1;

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

{

printf("fib %d\n", a);

fib = a+b;

a=b;

b=fib;

}

return 0;

}

#include

ReplyDelete#include

void main()

{

int a,b,c,i,n;

a=0;

b=1;

printf("Enter number :");

scanf("%d",&n);

if(n==1)

{

printf("\n fibonacci series\n");

printf("%d",a);

}

else if(n==2)

{

printf("\n fibonacci series\n");

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

}

else

{

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

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

{

c=a+b;

a=b;

b=c;

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

}

}

getch();

}

Jst Change the for loop

ReplyDeletefor(i=0;i<n-2;i++)

#include

ReplyDeletevoid main()

{ int n,i,a,b,c;

printf("enter the range");

scanf ("%d",&n);

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

{c=a+b;

a=b;

b=c;

printf("the fibonaci series is=%d",c)

}

getch();

}

logic is correct and simple but it's not working.

ReplyDeletevoid main()

ReplyDelete{

int a=-1,b=1,c,i;

scanf("%d",&n);

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

{

c=a+b;

a=b;

b=c;

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

}

getch()

}

#include

ReplyDelete#include

main()

{int a,b,i,n;

a=b=1;

printf("enter number of times u want to print fibb series");

scanf("%d",&n);

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

{if(i<=1)

printf("%d",1);

c=a+b;

a=b;

b=c;

printf("%d",c);

}

getch();

}

it will print

1 1 2 3 5 7 12 19.....

#include

ReplyDeletevoid main(){

int no,x=1,y=1,z,i;

printf("Enter number :");

scanf("%d",&no);

for(i=2;i<no;i++)

{

z=x+y;

x=y;

y=x;

}

printf("%d",Z);

getch();

}

}

This comment has been removed by the author.

ReplyDeletechek out this as well : c program to find fibonacci series using recursion

ReplyDelete

ReplyDelete2. Draw the flowchart and write c program to display Fibonacci series numbers