sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 23 of 98

Find Nth positive number whose digital root is X in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 206 Views

In this problem, we are given two integer values N and X. Our task is to create a program to Find Nth positive number whose digital root is X.Digital Root (X) is a single digit positive number which is found by adding digits of N recursively adding digits, till the sum becomes single digit.Let’s take an example to understand the problem, InputN = 5, X = 4Output40Solution ApproachA simple way to solve the problem is by counting the numbers with a digital root is X. For this, we will start from 1 and then check if the current number’s digital ...

Read More

Find Nth term (A matrix exponentiation example) in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 287 Views

In this problem, we are given an integer N and a recursive function that given Nth term as a function of other terms. Our task is to create a program to Find Nth term (A matrix exponentiation example).The function isT(n) = 2*( T(n-1) ) + 3*( T(n-2) ) Initial values are    T(0) = 1 , T(1) = 1Let’s take an example to understand the problem, InputN = 4Output41ExplanationT(4) = 2* (T(3)) + 3*(T(2)) T(4) = 2* ( 2*(T(2)) + 3*(T(1)) ) + 3*( 2* (T(1)) + 3*(T(0)) ) T(4) = 2*( 2*(2* (T(1)) + 3*(T(0))) + 3*(1) ) + ...

Read More

C++ program to find Nth term of series 1, 4, 15, 72, 420...

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 487 Views

In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1, 4, 15, 72, 420…Let’s take an example to understand the problem, InputN = 4Output72Solution ApproachA simple approach to solve the problem is the formula for the Nth term of the series. For this, we need to observe the series and then generalise the Nth term.The series can be seen as the product of factorial and a some variables, 1, 4, 15, 72, 420… 1!*(X1), 2!*(X2), 3!*(X3), 4!*(X4), 5!*(X5)... 1*(1), 2*(2), 6*(5/2), 24*(3), 120*(7/2)...Here, the series of product ...

Read More

C++ program to find Nth term of the series 0, 2, 4, 8, 12, 18...

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 408 Views

In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 0, 2, 4, 8, 12, 18…Let’s take an example to understand the problem, InputN = 5Output12Solution ApproachA simple approach to solve the problem is the formula for the Nth term of the series. For this, we need to observe the series and then generalise the Nth term.The formula of Nth term isT(N) = ( N + (N - 1)*N ) / 2Program to illustrate the working of our solution, Example#include using namespace std; int calcNthTerm(int N) { ...

Read More

C++ program to find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 ...

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 237 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

C++ program to Find Nth term of the series 1, 1, 2, 6, 24...

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 576 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#include using namespace std; int calcNthTerm(int N) {    if (N

Read More

C++ program to find Nth term of the series 1, 5, 32, 288 ...

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 410 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#include using namespace std; int calcNthTerm(int N) {    if (N

Read More

C++ program to find Nth term of the series 1, 6, 18, 40, 75, ....

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 296 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#include using namespace std; int calcNthTerm(int N) {    return ( (N*N*(N+1))/2 ); } int main() {    int N = 5;    cout

Read More

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

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 217 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#include using namespace std; int calcFact(int N) {    int fact = 1;    for (int i = 1; i

Read More

C++ program to find Nth term of the series 3, 14, 39, 84...

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 224 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#include using namespace std; int calcNthTerm(int N) {    return ( (N*N*N) + (N*N) + (N) ); } int main() {    int N = 6;    cout

Read More
Showing 221–230 of 975 articles
« Prev 1 21 22 23 24 25 98 Next »
Advertisements