Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 584 of 719
9K+ Views
C++ Tokens are the smallest individual units of a program.C++ is the superset of C and so most constructs of C are legal in C++ with their meaning and usage unchanged. So tokens, expressions, and data types are similar to that of C.Following are the C++ tokens : (most of c++ tokens are basically similar to the C tokens)KeywordsIdentifiersConstantsVariablesOperatorsKeywordsKeywords are reserved words which have fixed meaning, and its meaning cannot be changed. The meaning and working of these keywords are already known to the compiler. C++ has more numbers of keyword than C, and those extra ones have special working ... Read More
403 Views
In this program we have to add binary numbers given. there are n binary numbers and we have to add them all to give one binary number as an output.For this we will use binary addition logic and add all the terms from 1 to N one by one to gain the result.Input: "1011", "10", "1001" Output: 10110ExplanationThe easier method is by converting binary string to its decimal equivalent, then add them and convert into binary again. Here we will do the addition manually. We will use one helper function to add two binary strings. That function will be used ... Read More
837 Views
We can insert new node into the BST in recursive manner. In that case we return the address of the root of each subtree. Here we will see another approach, where parent pointer will need to be maintained. Parent pointer will be helpful to find ancestor of a node etc.The idea is to store the address of the left and right subtrees, we set parent pointers of the returned pointers after recursive call. This confirms that all parent pointers are set during insertion. The parent of root is set to null.Algorithminsert(node, key) −begin if node is null, then create ... Read More
3K+ Views
In this problem, you are given an integer array arr of size n and an integer S. Your task is to find an element k in the array such that if all the elements greater than k in the array are replaced with k, then the sum of all the elements of the resultant array becomes equal to S. If such an element exists, print it; otherwise, print -1. Scenario 1: Input: int S = 9; int arr[] = { 1, 3, 2, 5, 8 }; Output: ... Read More
167 Views
Here we will see one problem, suppose one array is given. There are n elements. We have to find one index, where frequency of even numbers of its left and the frequency of even numbers of its right side are same, or the frequency of odd numbers of its left is same as the frequency of odd numbers of its right. If no such result is there, return -1.Suppose the array is like {4, 3, 2, 1, 2, 4}. The output is 2. The element at index 2 is 2, there is only one odd number at left of it, ... Read More
715 Views
The C++ STL or Standard Template Library is a collection of general-purpose classes and functions with templates for implementing many algorithms and data structures such as vectors, lists, queues, and stacks. The 4 components of STL are: Containers, Algorithms, Iterators, and Functors. In this article, we will discuss the functions of the header that work on arrays, and are introduced in C++ 11 and later versions. C++ Header The algorithm header provides various built-in functions that implement algorithms such as searching, sorting, finding the maximum element, etc. These functions perform various operations on containers such ... Read More
401 Views
In this problem, our task is to find the area of the largest triangle that can be inscribed in a regular hexagon. Each side of the hexagon and triangle is of length a and b, respectively. Area of the Largest Triangle Inscribed in a Hexagon You can calculate the area of the largest triangle inscribed in a regular hexagon using the following formula: $$ Area\ of\ triangle\ inside\ hexagon\ = \frac{3\sqrt{3}}{4} \cdot a^2 $$ Derivation The first step is to establish a relation between a and b, as the value of a(side of the hexagon) is ... Read More
133 Views
Here we will see the area of largest square that can be inscribed in an ellipse. The square in ellipse will be like below −The area of ellipse is −Now, if x and y are same, thenSo area is −Example#include #include using namespace std; float area(float a, float b) { if (a < 0 || b < 0 ) //if values are is negative it is invalid return -1; float area = (4*(a*a + b*b)) / (a*a*b*b); return area; } int main() { float a = 4, b = 2; cout
159 Views
Here we will see how to get the area of the circumcircle of any triangle whose sides are given. Here the side AB is a, BC is b and CA is c, the radius is ‘r’.The radius r is same as −Example#include #include using namespace std; float area(float a, float b, float c) { if (a < 0 || b < 0 || c < 0) //if values are is negative it is invalid return -1; float s = (a + b + c) /2; float triangle = sqrt(s * (s - ... Read More
454 Views
Unique Triplets that Sum up to a Given Value In this article, we will discuss different approaches to find all the unique triplets that sum up to the given value. Before that, first understand the given problem. We have been given an integer array with N elements, along with a target value. Our task is to find unique or distinct triplets (i.e., three numbers) from an array, whose sum is the same as the target value. Let's take a scenario to understand the problem in a better way: Scenario 1 Input: arr ={1, 2, 3, 4, 5, 6, 7} ... Read More