Found 26504 Articles for Server Side Programming

C++ program to find Nth term of the series 5, 13, 25, 41, 61…

sudhir sharma
Updated on 15-Mar-2021 10:45:14

217 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

C++ program to find nth term of the series 5, 2, 13 41,...

sudhir sharma
Updated on 15-Mar-2021 10:43:50

210 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

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

sudhir sharma
Updated on 15-Mar-2021 10:42:43

173 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

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

sudhir sharma
Updated on 15-Mar-2021 10:41:39

164 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

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

sudhir sharma
Updated on 15-Mar-2021 10:40:07

260 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

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

sudhir sharma
Updated on 15-Mar-2021 10:38:54

347 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

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

sudhir sharma
Updated on 15-Mar-2021 10:37:36

531 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

Change x axes scale in matplotlib

Rishikesh Kumar Rishi
Updated on 15-Mar-2021 08:44:15

15K+ Views

Using plt.xticks, we can change the X-axis scale.StepsUsing plt.plot() method, we can create a line with two lists that are passed in its argument.Add text to the axes. Add the text *s* to the axes at location *x*, *y* in data coordinates, using plt.text() method, where the font size can be customized by changing the font-size value.Using xticks method, get or set the current tick locations and labels of the X-axis.To show the figure, use plt.show() method.Exampleimport matplotlib.pyplot as plt plt.plot([1, 2, 4], [1, 2, 4]) plt.text(2, 3, "y=x", color='red', fontsize=20) plt.xticks([1, 2, 3, 4, 5])   ... Read More

How to change fonts in matplotlib (python)?

Rishikesh Kumar Rishi
Updated on 15-Mar-2021 08:42:43

2K+ Views

Using plt.text() method, we can increase the font size.StepsUsing plt.plot() method, we can create a line with two lists that are passed in its argument.Add text to the axes. Add the text *s* to the axes at location *x*, *y* in data coordinates, using plt.text() method. Font size can be customized by changing the font-size value.To show the figure, use plt.show() method.Exampleimport matplotlib.pyplot as plt plt.plot([1, 2, 4], [1, 2, 4]) plt.text(2, 3, "y=x", color='red', fontsize=20) # Increase fontsize by increasing value. plt.show()Output

Python matplotlib multiple bars

Rishikesh Kumar Rishi
Updated on 15-Mar-2021 08:41:20

448 Views

We can use a user-defined method, autolabel, to annotate the axis value. Before that, we can initialize the fig and ax using plt.subplots() method.StepsCreate lists, labels, men_means, and women_means with different data elements.Return evenly spaced values within a given interval, using numpy.arrange() method.Set the width variable i.e., width=0.35.Create fig and ax variables using subplots method, where default nrows and ncols are 1.The bars are positioned at *x* with the given *align*\ment. Their dimensions are given by *height* and *width*. The vertical baseline is *bottom* (default 0), so create rect1 and rect2 using plt.bar() method.Set the Y-axis label using plt.ylabel() method.Set ... Read More

Advertisements