0% found this document useful (0 votes)
18 views1 page

C++ Fibonacci Series Generator Code

The document contains a C++ program that generates and prints the Fibonacci series up to a user-defined number. It uses a recursive function to calculate the Fibonacci numbers after printing the first two numbers (0 and 1). The user is prompted to enter a number, and the series is displayed accordingly.

Uploaded by

Aldo Valdivia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

C++ Fibonacci Series Generator Code

The document contains a C++ program that generates and prints the Fibonacci series up to a user-defined number. It uses a recursive function to calculate the Fibonacci numbers after printing the first two numbers (0 and 1). The user is prompted to enter a number, and the series is displayed accordingly.

Uploaded by

Aldo Valdivia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include<iostream>

using namespace std;

void FibonacciSeries(int num)

static int first_num = 0, second_num = 1, third_num;

if(num > 0)

third_num = first_num + second_num;

first_num = second_num;

second_num = third_num;

cout << third_num << endl;

FibonacciSeries(num - 1);

int main()

int num;

cout << "Enter random number to print fibonacci series:";

cin >> num;

cout << "Fibonacci Series for a given number: \n" << endl;

cout << "0" << endl;

cout << "1" << endl;

FibonacciSeries (num - 2); //number-2 is used because we have already print 2 numbers

return 0;

You might also like