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, 10, 30, 60, 99... trong C++

Cho dãy: 0, 10, 30, 60, 99, 150, 210, 280... Tìm số hạng thứ N.

Công thức

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

Mã nguồn C++

#include <iostream>
#include <cmath>
using namespace std;

int nthTerm(int n) {
    return 5 * n * n - 5 * n;
}

int main() {
    int N = 4;
    cout << nthTerm(N) << endl; // 60
    return 0;
}

Đầu ra

60