- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7347 Articles for C++
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
4K+ Views
In this problem, we are given two arrays date1[] and date2 consisting of 3 integers which denote the DD-MM-YYYY of daes. Our task is to find the number of days between two given dates.Let’s take an example to understand the problem, Inputdate1[] = {13, 3, 2021}, date2[] = {24, 5, 2023}Output802ExplanationThe difference is 2 years , 2 months (3 - 5) and 11 days.2*356 + (30 + 31) + 11 = 802Solution ApproachA simple solution to the problem is by looping, starting from the start date date1 to date2 counting the number of days. And returning the value. This approach ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
162 Views
In this problem, we are given an array divisors[] consisting of N integers which are the divisors of a number Num. Our task is to find the number from its divisors.The divisor array does not include 1 and the number.Let’s take an example to understand the problem, Inputdivisors[] = {3, 25, 5, 15}Output75ExplanationThe number 75 has divisors {3, 25, 5, 15}Solution ApproachTo solve the problem, we need to find the number Num using the smallest and largest divisors of the number.Num = smallest * largestFor this, we need to sort the array divisors[] and then find the product of elements ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
157 Views
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 5, 13, 25, 41, 61, …Let’s take an example to understand the problem,InputN = 5Output61ExplanationThe series is − 5, 13, 25, 41, 61…Solution ApproachA simple approach to solve the problem is by using the general formula for the nth term of the series. The Nth term is given by,Nth term = ( (N*N) + ((N+1)*(N+1)) )Program to illustrate the working of our solution,Example Live Demo#include using namespace std; int calcNthTerm(int N) { return ( ( (N + 1)*( N + 1) ) + (N*N) ) ; } int main() { int N = 7; cout
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
169 Views
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 5, 2, 19, 13, 41, 31, 71, 57…Let’s take an example to understand the problem, InputN = 5Output41ExplanationThe series is − 5, 2, 19, 13, 41, …Solution ApproachA simple approach to solve the problem is by using the general formula for the nth term of the series. The series has different formulas for even and odd values.The Nth term is given by, Nth term = (N-1)^2 + N, if N is even i.e N%2 == 0 Nth term ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
138 Views
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 3, 14, 39, 84…Let’s take an example to understand the problem,InputN = 4Output84Explanation4th term − ( (4*4*4) + (4*4) + 4 ) = 64 + 16 + 4 = 84Solution ApproachA 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) + (N*N) + (N))Program to illustrate the working of our solution,Example Live Demo#include using namespace std; int calcNthTerm(int N) { return ( (N*N*N) + (N*N) + (N) ); } int main() { int N = 6; cout
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
108 Views
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,InputN = 4Output384Explanation4th term − (4 * 4 * (4!) = 384Solution ApproachA 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 using namespace std; int calcFact(int N) { int fact = 1; for (int i = 1; i
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
190 Views
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1,6, 18, 40, 75 ...Let’s take an example to understand the problem,InputN = 4Output40Explanation4th term − (4 * 4 * 5 ) / 2 = 40Solution ApproachA 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 + 1) ) / 2Program to illustrate the working of our solution,Example Live Demo#include using namespace std; int calcNthTerm(int N) { return ( (N*N*(N+1))/2 ); } int main() { int N = 5; cout
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
137 Views
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1,5, 32, 288 ...Let’s take an example to understand the problem,InputN = 4Output288Explanation4th term − (4^4) + (3^3) + (2^2) + (1^1) = 256 + 27 + 4 + 1 = 288Solution ApproachA 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-1)^(N-1) ) + … + ( 2^2 ) + ( 1^1 )Program to illustrate the working of our solution,Example Live Demo#include using namespace std; int calcNthTerm(int N) { if (N
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
424 Views
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,InputN = 7Output720ExplanationThe series is − 1, 1, 2, 6, 24, 120, 720Solution ApproachA 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 using namespace std; int calcNthTerm(int N) { if (N
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
130 Views
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8…Let’s take an example to understand the problem, InputN = 7Output4Solution ApproachA simple approach to solve the problem is using a loop to find the term at the nth position. The terms will be updated by doubling after each iteration. And adding it to the term counter.Program to illustrate the working of our solution, Example#include using namespace std; int calcNthTerm(int N) { ... Read More