在本教程中,我们将讨论一个程序以查找系列0、11、28、51、79、115、156、203等的第N个项。
为此,我们将提供一个号码。我们的任务是在特定位置找到给定系列的术语。
#include <iostream>
#include <math.h>
using namespace std;
//计算系列的第n个项
int nthTerm(int n) {
   return 3 * pow(n, 2) + 2 * n - 5;
}
int main() {
   int N = 4;
   cout << nthTerm(N) << endl;
   return 0;
}输出结果
51