ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมเพื่อค้นหาเทอมที่ N ของชุดที่ 1, 6, 17,34, 56, 86, 121, 162, …
สำหรับเรื่องนี้เราจะมีเลขเด็ดมาให้ งานของเราคือค้นหาคำศัพท์สำหรับชุดที่กำหนด ณ ตำแหน่งนั้น
ตัวอย่าง
#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