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