- 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++
98 Views
This is a C++ program to perform integer partition for a specific case. In this program, a positive integer n is given, and shall have to generate all possible unique ways to represent n as sum of positive integers.AlgorithmBegin function displayAllUniqueParts(int m): 1) Set Index of last element k in a partition to 0 2) Initialize first partition as number itself, p[k]=m 3) Create a while loop which first prints current partition, then generates next partition. The loop stops when the current partition has all 1s. 4) Display current partition as displayArray(p, k + ... Read More
448 Views
This is a C++ program to compute Combinations using Recurrence Relation for nCr.AlgorithmsBegin function CalCombination(): Arguments: n, r. Body of the function: Calculate combination by using the formula: n! / (r! * (n-r)!. EndExample#include using namespace std; float CalCombination(float n, float r) { int i; if(r > 0) return (n/r)*CalCombination(n-1,r-1); else return 1; } int main() { float n, r; int res; coutn; coutr; res = CalCombination(n,r); cout
304 Views
This is a C++ program to generate a sequence of N characters for a given specific case.AlgorithmsBegin function GenerateSequence() generate a Sequence of N Characters for a Given Specific Case: Use rand() for generating random indexes. Store the first character directly into the sequence. If that sequence is used earlier, then it discards that and generates random index again. EndExample#include #include #include using namespace std; void GenerateSequence(char string[], int n, int l, char *sequence) { int i, j=0, k, in; for(i = 0; i < n; i++) { ... Read More
2K+ Views
This is a C++ program to generate all possible combinations of a given list of numbersAlgorithmsBegin Take the number of elements and the elements as input. function Combi(char a[], int reqLen, int s, int currLen, bool check[], int l) : If currLen>reqLen then Return Else if currLen=reqLen then Then print the new generated sequence. If s=l then Then return no further element is left. For every index there are two option: either proceed with a start as ‘true’ and recursively call Combi() with incremented value of ... Read More
90 Views
This is a C++ program to implement the Alexander Bogomolny’s UnOrdered Permutation Algorithm for elements from 1 to NAlgorithmsBegin function AlexanderBogomolny() to implement the Algorithms Arguments: Val[] = an array N = number of elements taken as input. K = level Body of the function: intialize l = -1 l = l+1 Val[k] = l if (l == N) Call function display(Val, N) else ... Read More
169 Views
This is a C++ program to find the number of occurrences of a given number using Binary Search approach.AlgorithmsBegin function Insert() to insert nodes into the tree: Arguments: root, d. Body of the function: Create node using data from argument list. If tree is completely empty, then insert new node as root. If d = tmp->data, increase the count of that particular node. If d < tmp->data, move the tmp pointer to the left child. If d ... Read More
455 Views
This is a C++ program to find the Mode in a data set.AlgorithmsBegin function insertinset() to insert data in the set. Create newnode and temp(t) node. Node to be inserted in the list using newnode. If head is null then assign new node to head and increase the count. During insertion perform insertion sort for sorting data. If the newnode->data is equal to any of the element present in the set, then just increment count. EndExample#include using namespace std; struct set // a structure set to declare ... Read More
153 Views
This is a C++ program to find ith largest number from a given list using Order-Statistic Algorithm.AlgorithmsBegin function Insert() to insert nodes into the tree: Arguments: root, d. Body of the function: If tree is completely null then insert new node as root. If d = tmp->data, increase the count of that particular node. If d < tmp->data, move the tmp pointer to the left child. If d > tmp->data, move the tmp pointer to the right child. End Begin ... Read More
123 Views
This is a C++ Program to find k numbers closest to Median of S, where S is a set of n numbers.AlgorithmsBegin function partition() for partitioning the array on the basis of values at high as pivot value: Arguments: a[]=an array. l=low H=high Body of the function: Declare variables pivot, in, i Initialize in = l Set pivot = h For i=l to h-1 if(a[i] < a[pivot]) swap a[i] and a[in]) increment in. ... Read More
97 Views
This is a C++ program to find Second Smallest of n elements with given complexity constraint.AlgorithmBegin function SecondSmallest() : /* Arguments to this function are: A pointer array a. Number of elements n */ // Body of the function: A variable s1 is declared as to keep track of smallest number. A variable s2 is declared as to keep track of second smallest number. Initialize both s1 and s2 with INT_MAX. Traverse ... Read More