本文共 1596 字,大约阅读时间需要 5 分钟。
32位系统能够识别多达内存
Given N and we have to print lucas series upto N terms.
给定N,我们必须打印lucas系列,最多N个术语。
The Lucas series is an integer series very similar to the Fibonacci series, named after the French mathematician . 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系列的整数系列,该系列以法国数学家名字命名。 Lucas系列的每一项定义为系列的前两项的总和,前两项分别为2和1。 卢卡斯系列和斐波那契系列彼此互补。 该系列的术语是黄金比例的整数幂,四舍五入到最接近的整数。 下面给出的代码可查找最多n次迭代的Lucas系列术语 。
Code
码
/*Program to print the Lucas series for n terms.*/#includeusing 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 < <<"Lucas series for "<< n<< " terms is:"< << 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: 5Lucas series for 5 terms is:21347Second run:Enter the number of terms desired in the lucas series: 10Lucas series for 10 terms is:213471118294776
翻译自:
32位系统能够识别多达内存
转载地址:http://fpvzd.baihongyu.com/