answersLogoWhite

0


Best Answer

Yes, you can. To generate the Fibonacci sequence, you start with the first two numbers in the sequence, usually 0 and 1. The remainder of the sequence is the sum of the previous two numbers in the sequence:

The following function will generate n terms of the sequence using first and second as the first two numbers in the sequence:

void fibonacci (int n, int first=0, int second=1) {

for (int term=0; term

int sum = first + second;

printf ("%d, ", first);

// prepare for next iteration...

first = second;

second = sum;

}

printf ("\b\b \n"); // backspace over final comma and overwrite with space

}

User Avatar

Wiki User

6y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

#include<iostream>

int main()

{

int x=0, y=1;

std::cout<<x<<" ";

std::cout<<y<<" ";

while( y<1000000 )

{

std::cout<<(y+=x)<<" ";

x=y-x;

}

std::cout<<std::endl;

return(0);

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include<constream.h>

void main()

{

int a,b,i=1;

cout<<"Enter a no till when u want print non fibonaci numbers\t:"

cin>>c;

cout<<"\n Non fibonaci nos \n:"

for(a=0,b=1;i<=c;i++)

{

if(i==(a=a+b))

continue;

if(i==(b=a+b))

continue;

cout<<i \t;

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<iostream.h>

int main()

{

int first,sec,third;

int n;

cout<<"enter how many elements (>5).";

cin>>n;

first=0;

sec=1;

cout<<"the series is"<<first<<sec;

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

{

third=first+sec;

cout<<third;

first=sec;

sec=third;

}

return 0;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a program to print the Fibonacci series in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Program to generate Fibonacci series using storage class in c plus plus?

i dn't know. haha


Can you have the program in C plus plus for recursive function generating a series of terms?

Yes, this can be done. For example for Fibonacci series. You will find plenty of examples if you google for the types of series you need to be generated.


Write a program in BASIC to find the sum of the series s equals 2 plus 4 plus . plus 100?

10 print "That is not a question." 20 print "That is a command." 30 end


Create a c plus plus program to generate Fibonacci series?

#include #include void main() { clrscr() int a=0,b=1,c,i,n; coutn cout


What is the name of the series 1 plus 1 plus 2 plus 3 plus 5 plus 8 plus 13 plus 21 plus 34 plus .................................?

That's the beginning of the Fibonacci series.


C plus plus program to print number patterns?

bghjg


Do I need a C plus plus program to print PASCAL's triangle?

No.


What is the name of the series 1 plus 1 plus 2 plus 3 plus 5 plus 8 plus 13 plus 21 plus 34 plus .........?

It's Fibonacci's


What are the steps in c plus plus program to print word computer?

std::cout&lt;&lt;"computer"&lt;&lt;std::endl;


How do you print a series 1 plus 3 plus 5 plus 7 in basic?

EXAMPLE 1 PRINT 1+3+5+7 EXAMPLE 2 FOR num% = 1 TO 7 STEP 2 total%=total%+num% NEXT PRINT total%


A c plus plus program to find Fibonacci series?

#include&lt;iostream&gt; int main() { int x=0, y=1; std::cout&lt;&lt;x&lt;&lt;" "; std::cout&lt;&lt;y&lt;&lt;" "; while( y&lt;1000000 ) { std::cout&lt;&lt;(y+=x)&lt;&lt;" "; x=y-x; } std::cout&lt;&lt;std::endl; return(0); }


How do you write a c plus plus recursion program to find fibonacci series?

#include&lt;iostream&gt; unsigned fib (unsigned term, unsigned a=0, unsigned b=1) { if (term&lt;1) return a; return fib (--term, a+b, a); } int main() { std::cout &lt;&lt; "Fibonacci (1000th term): " &lt;&lt; fib (1000) &lt;&lt; std::endl; }