 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to find Nth term of the series 0, 2, 4, 8, 12, 18…
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 0, 2, 4, 8, 12, 18…
Let’s take an example to understand the problem,
Input
N = 5
Output
12
Solution Approach
A simple approach to solve the problem is the formula for the Nth term of the series. For this, we need to observe the series and then generalise the Nth term.
The formula of Nth term is
T(N) = ( N + (N - 1)*N ) / 2
Program to illustrate the working of our solution,
Example
#include <iostream> using namespace std; int calcNthTerm(int N) {    return (N + N * (N - 1)) / 2; } int main() {    int N = 10;    cout<<N<<"th term of the series is "<<calcNthTerm(N);    return 0; } Output
10th term of the series is 50
Advertisements
 