A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C++ program to print Lucas series upto N terms
Q:

C++ program to print Lucas series upto N terms

0

Given N and we have to print lucas series upto N terms.

Lucas series

The Lucas series is an integer series very similar to the Fibonacci series, named after the French mathematician François Édouard Anatole Lucas. Each term of the Lucas series is defined as the sum of the previous two terms of the series with the first two terms being 2 and 1 respectively. The Lucas series and Fibonacci series are complementary to each other. The terms of the series are integer powers of the golden ratio rounded to the closest whole number. Given below is the code to find the Terms of the Lucas series up to n iterations.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Code

/*Program to print the Lucas series for n terms.*/

#include <iostream>
using namespace std;

int main()
{
	int n, i, t1 = 2, t2 = 1, tn;
	cout << "Enter the number of terms desired in the lucas series: ";
	cin >> n;
	
	if (n == 1)
		cout << endl << 2 << endl;
	else if (n == 2)
		cout << endl << 2 << endl << 1 << endl;
	else if (n > 2)
	{
		cout <<endl<<"Lucas series for "<< n<< " terms is:"<<endl<< t1 << endl << t2 << endl;
		for (i = 0; i < n-2; i++)
		{
			tn = t1 + t2;
			cout << tn << endl;
			t1 = t2;
			t2 = tn;

		}
	}

	return 0;
}

Output

First run:
Enter the number of terms desired in the lucas series: 5

Lucas series for 5 terms is:
2
1
3
4
7

Second run:
Enter the number of terms desired in the lucas series: 10

Lucas series for 10 terms is:
2
1
3
4
7
11
18
29
47
76

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now