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

}

## 61 comments:

thanks.......

thanks

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

wrong!!!!!

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

if you take

a=-1

b=1

means u don't need to print a,b

wow thanks its totally right :)

mind blowing its right

thanku

dis is wrong dude ;

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

I hope this solves your problem

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

}

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

}

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

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

good one re, thank you

thanks..

Thanks!!!!!!!!!!!

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

}

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

#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

fibonacci series starts with 1 never with 0...

Thank you.

a= -1

b=1

sum = a+b

a=b

b=sum

fibonacci 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");

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..

can explain the running of loop?

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

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

}

can anyone tell how to write reverse fabonnaci 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=n;i<n;i--)

{

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

c=a+b;

a=b;

b=c;

}

getch();

}

idiot

making it complex

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

#include

main()

{

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

so 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

hi, u have oversimplified...

the 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....

:-)

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

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

remaining thnks are ok................

/* 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);

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"

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

}

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

}

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

i think it's not proper output

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

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

}

#include

main()

{

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

}

}

Its simplest n perfect code...!!!

int main()

{

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

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

}

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

Jst Change the for loop

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

#include

void 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.

void main()

{

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

#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.....

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

void main()

{

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

}

}

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

#include

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

}

}

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

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

can u wtite a code to print the fibonacci series within a specified range by the user. like if user enters 10 as the range,program should print 0,1,1,2,3,5.8

## Post a Comment

Dont SPAM