- 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 7346 Articles for C++
551 Views
Both strcat() and strncat() are predefined string functions in C++. Details about these are given as follows.strcat()This function is used for concatenation. It appends a copy of the source string at the end of the destination string and returns a pointer to the destination string. The syntax of strcat() is given as follows.char *strcat(char *dest, const char *src)A program that demonstrates strcat() is given as follows.Example Live Demo#include #include using namespace std; int main() { char str1[20] = "Mangoes are "; char str2[20] = "yellow"; strcat(str1, str2); cout
323 Views
In C++, strchr() is a predefined function. It is used for string handling and it returns the first occurance of a given character in the string provided.The syntax of strchr() is given as follows.char *strchr( const char *str, int c)In the above syntax, str is the string that contains the character c. The strchr() function finds the first occurrence of c in str.A program that demonstrates the strchr() function is given as follows.Example Live Demo#include #include using namespace std; int main() { char str[] = "strings"; char * c = strchr(str,'s'); cout
966 Views
Tree traversal is a form of graph traversal. It involves checking or printing each node in the tree exactly once. The preorder traversal of a binary search tree involves visiting each of the nodes in the tree in the order (Root, Left, Right).An example of Preorder traversal of a binary tree is as follows.A binary tree is given as follows.Preorder Traversal is: 5 3 2 4 8 9A program to perform preorder non-recursive traversal is given as follows.Example Live Demo#include #include using namespace std; struct node { int data; struct node *left; struct node *right; }; struct ... Read More
5K+ Views
The factorial of a positive integer n is equal to 1*2*3*...n. Factorial of a negative number does not exist. Here a C++ program is given to find out the factorial of a given input using dynamic programming.AlgorithmBegin fact(int n): Read the number n Initialize i = 1, result[1000] = {0} result[0] = 1 for i = 1 to n result[i] = I * result[i-1] Print result EndExample Code#include using namespace std; int result[1000] = {0}; int fact(int n) { if (n >= 0) { result[0] = 1; for (int i = 1; i
2K+ Views
Heap Sort is based on the binary heap data structure. In the binary heap the child nodes of a parent node are smaller than or equal to it in the case of a max heap, and the child nodes of a parent node are greater than or equal to it in the case of a min heap.An example that explains all the steps in Heap Sort is as follows.The original array with 10 elements before sorting is −207154101590237725This array is built into a binary max heap using max-heapify. This max heap represented as an array is given as follows.907720542515123710The root ... Read More
4K+ Views
Tree traversal is a form of graph traversal. It involves checking or printing each node in the tree exactly once. The postorder traversal of a binary search tree involves visiting each of the nodes in the tree in the order (Left, Right, Root).An example of postorder traversal of a binary tree is as follows.A binary tree is given as follows.Postorder Traversal is: 1 5 4 8 6The program to perform post-order recursive traversal is given as follows.Example Live Demo#include using namespace std; struct node { int data; struct node *left; struct node *right; }; struct node *createNode(int val) ... Read More
13K+ Views
Tree traversal is a form of graph traversal. It involves checking or printing each node in the tree exactly once. The inorder traversal of a binary search tree involves visiting each of the nodes in the tree in the order (Left, Root, Right).An example of Inorder traversal of a binary tree is as follows.A binary tree is given as follows.Inorder Traversal is: 1 4 5 6 8The program to perform in-order recursive traversal is given as follows.Example Live Demo#include using namespace std; struct node { int data; struct node *left; struct node *right; }; struct node *createNode(int val) ... Read More
7K+ Views
Tree traversal is a form of graph traversal. It involves checking or printing each node in the tree exactly once. The preorder traversal of a binary search tree involves visiting each of the nodes in the tree in the order (Root, Left, Right).An example of Preorder traversal of a binary tree is as follows.A binary tree is given as follows.Preorder Traversal is: 6 4 1 5 8The program to perform pre-order recursive traversal is given as follows.Example Live Demo#include using namespace std; struct node { int data; struct node *left; struct node *right; }; struct node *createNode(int val) ... Read More
248 Views
Two matrices are said to be multiplicable if they can be multiplied. This is only possible if the number of columns of the first matrix is equal to the number of rows of the second matrix. For example.Number of rows in Matrix 1 = 3 Number of columns in Matrix 1 = 2 Number of rows in Matrix 2 = 2 Number of columns in Matrix 2 = 5 Matrix 1 and Matrix 2 are multiplicable as the number of columns of Matrix 1 is equal to the number of rows of Matrix 2.A program to check the ... Read More
9K+ Views
The determinant of a square matrix can be computed using its element values. The determinant of a matrix A can be denoted as det(A) and it can be called the scaling factor of the linear transformation described by the matrix in geometry.An example of the determinant of a matrix is as follows.The matrix is: 3 1 2 7 The determinant of the above matrix = 7*3 - 2*1 = 21 - 2 = 19 So, the determinant is 19.The program to compute the determinant of a matrix is as follows.Example Live Demo#include #include using namespace std; int determinant( int matrix[10][10], int ... Read More