n-th term in series 2, 12, 36, 80, 150….in C++

C++Server Side ProgrammingProgramming

In this tutorial, we are going to write a program that finds the n-th number in the series 2, 12, 36, 80, 150...

If you clearly observe the series, you will find that the n-th number is n2 + n3,n > 0

Example

Let's see the code.

 Live Demo

#include <bits/stdc++.h>
using namespace std;
int getNthTerm(int n) {
   return (n * n) + (n * n * n);
}
int main() {
   int n = 7;
   cout << getNthTerm(n) << endl;
   return 0;
}

Output

If you run the above code, then you will get the following result.

392

Conclusion

If you have any queries in the tutorial, mention them in the comment section.

raja
Published on 29-Jun-2021 09:28:01
Advertisements