Computer Science, asked by piyushpriyadarshan03, 4 months ago

write a Java program to display the first ten number of series 5,10,17 to n term​ pls hlp fast

Answers

Answered by Muskansolanki555
1

Explanation:

Input: N = 4

Output: 82

For N = 4

4th Term = ( 4 * 4 + 2 * 4 + 2)

= 26

Input: N = 10

Output: 122

Approach: The generalized Nth term of this series:

nth\: Term\: of\: the\: series\: = n^2+2n+2

Below is the required implementation:

// CPP program to find the N-th term of the series:

// 5, 10, 17, 26, 37, 50, 65, 82, ...

#include <iostream>

#include <math.h>

using namespace std;

// calculate Nth term of series

int nthTerm(int n)

{

return pow(n, 2) + 2 * n + 2;

}

// Driver Function

int main()

{

int N = 4;

cout << nthTerm(N);

return 0;

}

Output:

26

Time Complexity: O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

Similar questions