32位系统能够识别多达内存_C ++程序可打印多达N个术语的卢卡斯系列

32位系统能够识别多达内存

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

给定N,我们必须打印lucas系列,最多N个术语。

卢卡斯系列 (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.

Lucas系列是一个非常类似于Fibonacci系列的整数系列,该系列以法国数学家FrançoisÉdouardAnatole Lucas的名字命名。 Lucas系列的每一项定义为系列的前两项的总和,前两项分别为2和1。 卢卡斯系列和斐波那契系列彼此互补。 该系列的术语是黄金比例的整数幂,四舍五入到最接近的整数。 下面给出的代码可查找最多n次迭代的Lucas系列术语

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


翻译自: https://www.includehelp.com/cpp-programs/print-Lucas-series-upto-n-terms.aspx

32位系统能够识别多达内存

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值