# n-th term of series 1, 17, 98, 354…… in C++

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

The given series is 1, 17, 98, 354...

If you clearly observe the series, you will find that the n-th number is equal to the 4 powers.

Let's see the pattern.

1 = 1 ^ 4
17 = 1 ^ 4 + 2 ^ 4
98 = 1 ^ 4 + 2 ^ 4 + 3 ^ 4
354 = 1 ^ 4 + 2 ^ 4 + 3 ^ 4 + 4 ^ 4
...

## Algorithm

• Initialise the number N.
• Initialise the result to 0.
• Write a loop that iterates from 1 to n.
• Add 4th power current number to the result.
• Print the result.

## Implementation

Following is the implementation of the above algorithm in C++

#include <bits/stdc++.h>

using namespace std;

int getNthTerm(int n) {
int nthTerm = 0;
for (int i = 1; i <= n; i++) {
nthTerm += i * i * i * i;
}
return nthTerm;
}
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.

4676