C++ 中查找级数 3、12、29、54、86、128、177、234,……的第 N 项的程序
在本教程中,我们将讨论一个查找级数 3、12、29、54、86、128、177、234,…… 的第 N 项的程序
为此,我们将提供一个数字。我们的任务是查找该特定位置上给定级数的项。
例如
#include <iostream>
#include <math.h>
using namespace std;
//calculating nth term of given series
int nthTerm(int n) {
return 4 * pow(n, 2) - 3 * n + 2;
}
int main() {
int N = 4;
cout << nthTerm(N) << endl;
return 0;
}输出
54
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP