用 C++ 编写程序查找级数 1、6、17、34、56、86、121、162、… 的第 N 项


在本教程中,我们将讨论一个程序,该程序用于查找级数 1、6、17、34、56、86、121、162、… 的第 N 项

为此,我们将获得一个数字。我们的任务是查找特定位置该级数的项。

示例

 实时演示

#include <iostream>
#include <math.h>
using namespace std;
//calculating nth term of given series
int nthTerm(int n) {
   return 3 * pow(n, 2) - 4 * n + 2;
}
int main() {
   int N = 4;
   cout << nthTerm(N) << endl;
   return 0;
}

输出

34

更新于: 2020 年 5 月 4 日

98 次浏览

开启您的 职业

通过完成课程获取证书

开始
广告
© . All rights reserved.