C++ program to find Nth term of the series 1, 8, 54, 384…

C++Server Side ProgrammingProgramming

In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1,8, 54, 384 ...

Let’s take an example to understand the problem,

Input

N = 4

Output

384

Explanation

4th term − (4 * 4 * (4!) = 384

Solution Approach

A simple approach to solve the problem is by using the general formula for the nth term of the series. The formula for,

Nth term = ( N * N * (N !) )

Program to illustrate the working of our solution,

Example

 Live Demo

#include <iostream>
using namespace std;
int calcFact(int N) {
   int fact = 1;
   for (int i = 1; i <= N; i++)
   fact = fact * i;
   return fact;
}
int calcNthTerm(int N) {
   return ( N*N*(calcFact(N)) );
}
int main() {
   int N = 5;
   cout<<N<<"th term of the series is "<<calcNthTerm(N);
   return 0;
}

Output

5th term of the series is 3000
raja
Published on 15-Mar-2021 10:40:39
Advertisements