Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
C++ Articles
Page 201 of 597
Program to find Nth term divisible by a or b in C++
In this problem, we are given three numbers A, B, and N. Our task is to create a program to find Nth term divisible by A or B in C++.Problem DescriptionThe Nth Term divisible by A or B. Here, we will find the term n number term which is divisible by number A or B. For this, we will count till nth numbers that are divisible by A or B.Let’s take an example to understand the problem, InputA = 4, B = 3, N = 5Output9ExplanationThe terms the are divisible by 3 and 4 are −3, 4, 6, 8, 9, ...
Read MoreProgram to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++
In this problem, we are given a number N. Our task is to create a program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++.Problem descriptionTo find the Nth term of the given series−0, 0, 2, 1, 4, 2, 6, 3, 8 .... N TermsWe will find the general term of the series.Let’s take an example to understand the problem, InputN = 8Output3Solution ApproachTo find the general term of the series, we need to closely observe the series. This series is a bit difficult to recognize as it is a mixture of two ...
Read MoreProgram to find N-th term of series 0, 7, 8, 33, 51, 75, 102, 133...in C++
In this tutorial, we will be discussing a program to find N-th term of series 0, 7, 8, 33, 51, 75, 102, 133...For this, we will be provided with a number. Our task is to find the term for the given series at that particular position.Example#include #include using namespace std; //calculating nth term of series int nthTerm(int n) { return 2 * pow(n, 2) + n - 3; } int main() { int N = 4; cout
Read MoreProgram to find N-th term of series 0, 10, 30, 60, 99, 150, 210, 280...in C++
In this tutorial, we will be discussing a program to find N-th term of series 0, 10, 30, 60, 99, 150, 210, 280...For this, we will be provided with a number. Our task is to find the term for the given series at that particular position.Example#include #include using namespace std; //calculating nth term of series int nthTerm(int n) { return 5 * pow(n, 2) - 5 * n; } int main() { int N = 4; cout
Read MoreProgram to find N-th term of series 1, 6, 17, 34, 56, 86, 121, 162, …in C++
In this tutorial, we will be discussing a program to find N-th term of series 1, 6, 17, 34, 56, 86, 121, 162, …For this, we will be provided with a number. Our task is to find the term for the given series at that particular position.Example#include #include using namespace std; //calculating nth term of given series int nthTerm(int n) { return 3 * pow(n, 2) - 4 * n + 2; } int main() { int N = 4; cout
Read MoreComplex Number Multiplication in C++
Suppose we have two strings that are representing complex numbers, we have to parse them and perform complex number multiplication, then return result as a string.So if the input is like “1+-1i” and “1+-1i”, then the result will be “0+-2i”.To solve this, we will follow these steps −aa := a pair of real and imaginary of first complex numberbb := a pair of real and imaginary of second complex numberx := aa.real * bb.real – aa.img*bb.imgy := aa.real * bb.img + aa.img*bb.realreturn the string as “x+yi”Let us see the following implementation to get better understanding −Example#include using namespace std; ...
Read MoreHow to find common elements between two Arrays using STL in C++?
In this tutorial, we will be discussing a program to understand how to find common elements between two arrays using STL in C++.To find the common elements between two given arrays we will be using the set_intersetion() method.Example#include using namespace std; int main(){ //defining the array int arr1[] = { 1, 45, 54, 71, 76, 12 }; int arr2[] = { 1, 7, 5, 4, 6, 12 }; int n1 = sizeof(arr1) / sizeof(arr1[0]); int n2 = sizeof(arr2) / sizeof(arr2[0]); sort(arr1, arr1 + n1); sort(arr2, arr2 + n2); cout
Read MoreBeautiful Array in C++
Suppose for some fixed value of N, an array A is beautiful when it is a permutation of the integers 1, 2, ..., N, such that −For every i < j, there is no such k with i < k < j such that A[k] * 2 = A[i] + A[j].Suppose we have N, we have to find any beautiful array A.So if the input is like 5, then the output will be [3, 1, 2, 5, 4]To solve this, we will follow these steps −Create one array called ret, insert 1 into retwhile size of ret < Ncreate an ...
Read MoreBeautiful Arrangement in C++
Suppose we have N integers from 1 to N. We will define a beautiful arrangement as an array that is constructed by these N numbers completely if one of the following is true for the ith position (1
Read MoreWrite a program to Calculate Size of a tree - Recursion in C++
In this problem, we are given a tree and our task is to create a program to calculate the size of the tree using recursion.The size of a tree is the total number of nodes present in the tree.Let’s take an example to understand the problem, The size of the above tree is 5.To find the size of the tree, we will have to add the size of left subtree and right subtree and then increment it by 1. The recursive function will be called for both left and right subtrees of the tree. And if no subtree is found ...
Read More