C++ Program To Find Nth Term Of The Series 1, 1, 2, 6, 24…

Có thể bạn quan tâm

  • Home
  • Whiteboard
  • Online Compilers
  • Practice
  • Articles
  • AI Assistant
  • Jobs
  • Tools
  • Corporate Training
  • Courses
  • Certifications
Menu Categories Login
  • Switch theme
  • SQL
  • HTML
  • CSS
  • Javascript
  • Python
  • Java
  • C
  • C++
  • PHP
  • Scala
  • C#
  • Tailwind CSS
  • Node.js
  • MySQL
  • MongoDB
  • PL/SQL
  • Swift
  • Bootstrap
  • R
  • Machine Learning
  • Blockchain
  • Angular
  • React Native
  • Computer Fundamentals
  • Compiler Design
  • Operating System
  • Data Structure and Algorithms
  • Computer Network
  • DBMS
  • Excel
Technical Questions and Answers
  • 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 1, 1, 2, 6, 24… 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,1, 2, 6, 24, ...

Let’s take an example to understand the problem,

Input

N = 7

Output

720

Explanation

The series is − 1, 1, 2, 6, 24, 120, 720

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−1)!

Program to illustrate the working of our solution,

Example

 Live Demo

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

Output

8th term of the series is 5040 sudhir sharma sudhir sharma Updated on: 2021-03-15T10:37:36+05:30

556 Views

Kickstart Your Career

Get certified by completing the course

Get Started Print Page Previous Next Advertisements

Từ khóa » C++ 1 2