- 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++
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
291 Views
In this tutorial, we are going to write a program that finds all the pairs whose sum is equal to the given number in the binary search tree.We are going to store and values of trees in two different lists to find the pairs. Let's see the steps to solve the problem.Create a struct node for a binary tree.Write a function to insert a new node into the binary search tree.Remember, in the binary search tree all the elements that are less than root are smaller, and right are larger.Initialize two empty lists to store the left and right nodes ... Read More
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
735 Views
In this tutorial, we are going to write a program that finds all the divisors of a natural number. It's a straightforward problem. Let's see the steps to solve it.Initialize the number.Write a loop that iterates from 1 to the square root of the given number.Check whether the given number is divisible by the current number or not.If the above condition satisfies, then print the current number and given_number/current_number.ExampleLet's see the code. Live Demo#include using namespace std; void findDivisors(int n) { for (int i = 1; i
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
5K+ Views
In this tutorial, we are going to write a program that finds all the divisors of a natural number. It's a straightforward problem. Let's see the steps to solve it.Initialize the number.Write a loop that iterates from 1 to the given number.Check whether the given number is divisible by the current number or not.If the above condition satisfies, then print the current number.ExampleLet's see the code. Live Demo#include using namespace std; void findDivisors(int n) { for (int i = 1; i
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
300 Views
In this tutorial, we are going to write a program that finds the triplet in the array whose sum is equal to the given number.Let's see the steps to solve the problem.Create the array with dummy data.Write three inner loops for three elements that iterate until the end of the array.Add the three elements.Compare the sum with 0.If both are equal, then print the elements and break the loops.ExampleLet's see the code. Live Demo#include using namespace std; void findTripletsWithSumZero(int arr[], int n){ bool is_found = false; for (int i = 0; i < n-2; i++) { ... Read More
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
163 Views
In this tutorial, we are going to write a program that finds the number whose XOR operation with the given number is maximum.We are assuming the number of bits here is 8.The XOR operation of different bits gives you the 1 bit. And the XOR operation between the same bits gives you the 0 bit.If we find the 1's complement of the given number, then that's the number we are looking for.ExampleLet's see the code. Live Demo#include using namespace std; int findNumberWithMaximumXOR(int X) { return ((1
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
551 Views
In this tutorial, we are going to write a program that finds the triplet in the array whose sum is equal to the given number.Let's see the steps to solve the problem.Create the array with dummy data.Write three inner loops for three elements which iterate until the end of the array.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code. Live Demo#include using namespace std; bool findTriplet(int arr[], int arr_size, int sum) { for (int i = 0; i < arr_size - 2; i++) { ... Read More
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
137 Views
In this tutorial, we are going to write a program that finds the triplet in the linked list whose sum is equal to the given number.Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Write three inner loops for three elements which iterate until the end of the linked list.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code. Live Demo#include using namespace std; class Node { public: int data; Node* next; ... Read More
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
235 Views
In this tutorial, we are going to write a program that finds the peak element in the given arrayThe peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Initialize the array with dummy data.Check for the first element and last element for the peak element condition.Iterate over the array from the second element.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Print the resultExampleLet's see the code. Live Demo#include using namespace std; int findPeakElement(int arr[], int n) { if ... Read More
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
259 Views
In this tutorial, we are going to write a program that finds the peak element in the given linked list.The peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Check for the base cases like whether the linked list is empty or of length 1.Store the first element in a variable called previous.Iterate over the linked list.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Update the ... Read More
![Hafeezul Kareem](https://www.tutorialspoint.com/assets/profiles/120468/profile/60_159160-1581501828.jpg)
289 Views
In this tutorial, we are going to write a program that finds the peak element in a 2D array.An element is called a peak element if all the elements around it are smaller than the element.Let's see the steps to solve the problem.Initialize the 2D array with dummy data.Iterate over the 2D array.First, check the corner elements of the 2D array.Next, write the conditions for the first and last rows of the 2D array.Now, check for the first and last columns of the 2D array.And finally, check the middle elements.In each case, we have to compare the current element with ... Read More