answersLogoWhite

0

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

7y ago

What else can I help you with?

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<<"computer"<<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<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); }


C program to print numbers 1 to n?

how do we use loops in c plus plus programing and what are basic differences between do,for and while loop