C++ Program To Find Nth Term Of The Series 1, 1, 2, 6, 24…
- Home
- Whiteboard
- Online Compilers
- Practice
- Articles
- AI Assistant
- Jobs
- Tools
- Corporate Training
- Courses
- Certifications
- Switch theme
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
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 = 7Output
720Explanation
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 Updated on: 2021-03-15T10:37:36+05:30 556 Views
Kickstart Your Career
Get certified by completing the course
Get StartedTừ khóa » C++ 1 2
-
C++ Why Does ((1 / 2) * 2) Return 0 [duplicate] - Stack Overflow
-
1%2 - Modulus Question - C++ Forum
-
C++ : Calculate The Series (1) + (1+2) + … + (1+2+3+...+n)
-
C++ Basics - C++ Programming Tutorial
-
Is .5 Equal To 1/2 In The C Language? - Quora
-
Modulo Operator (%) In C/C++ With Examples - GeeksforGeeks
-
A Short Introduction To Computer Programming, Using C++
-
BASICs Of C/C++ Programming
-
10 Common Programming Mistakes In C++ 1 - UCR CS
-
C++ Program To Calculate Sum Of Natural Numbers - Programiz
-
4. Basic Declarations And Expressions - Practical C++ Programming ...
-
Plus One - LeetCode
-
1/2 Should Not Equal Zero - Musing Mortoray
-
[PDF] Some Practice Problems For The C++ Exam And Solutions For The ...