Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C++

Tìm số hạng thứ N của dãy 0, 9, 22, 39, 60... trong C++

Cho dãy: 0, 9, 22, 39, 60, 85, 114, 147... Tìm số hạng thứ N.

Công thức

T_N = 2*N^2 + 3*N - 5.

Mã nguồn C++

#include <iostream>
using namespace std;

int findNTerm(int N) {
    return 2*N*N + 3*N - 5;
}

int main() {
    int N = 8;
    cout << N << "th term of the series is " << findNTerm(N);
    return 0;
}

Đầu ra

8th term of the series is 147