- 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++
232 Views
Here we will see the area of largest triangle which is inscribed in regular hexagon. Each side of the hexagon is ‘a’, and each side of the triangle is ‘b’.From this diagram we can see that if we make one triangle using one side of hexagon, then these two triangles are making each sides into two parts. We can see two right angled triangles also. From the Pythagorus formula, we can say that −So the area is −Example#include #include using namespace std; float area(float a) { if (a < 0 ) //if value is negative it is ... Read More
69 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
70 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
318 Views
Here we will see one interesting problem. We have an array with some elements. One sum value is given. Our task is to find triplets from the array, and whose sum is same as the given sum. Suppose the array is {4, 8, 63, 21, 24, 3, 6, 1, 0}, and the sum value is S = 18. So the triplets will be {4, 6, 8}. If more than one triplet is present, it will show all of them.AlgorithmgetTriplets(arr, n, sum) −Begin define one array to store triplets, say trip_arr define one set unique_trip to store unique triplets. ... Read More
309 Views
Here we will see some advantaged and disadvantages of vector over array in C++.The vector is template class. This is C++ only constructs. The Arrays are built-in language construct. Arrays are present in different languages.Vectors are implemented as dynamic arrays with list interface, arrays can be implemented using static or dynamic way with primitive datatypes.Example#include #include using namespace std; int main() { int array[10]; //statically allocated array int* arr = new int[10]; //dynamically allocated array vector vec; }Array sizes are fixed. When one array is created, we cannot change the size. The size of the vector is ... Read More
705 Views
Here we will see how to perform the matrix addition and subtraction using multithreaded environment. The pthread is used to execute multiple threads simultaneously in C or C++.There are two matrices A and B. Order of each matrix is (m x n). Each thread will take each row, and perform addition or subtraction. So for m rows, there are m different threads.Example#include #include #include #include #define CORE 3 #define MAX 3 using namespace std; int AMat[MAX][MAX] = {{10, 20, 30}, {40, 50, 60}, {70, 80, 50} }; int BMat[MAX][MAX] = {{80, 60, 20}, {30, ... Read More
113 Views
Here we will see how to get the sum of the series with n-th term as n2 – (n-1)2. The recurrence relation is like below −Tn = n2 − (n−1)2So the series is −We need to find S mod (109 + 7), where S is the sum of all terms of the given series.Example#include #define X 1000000007 using namespace std; long long getSum(long long n) { return ((n % X) * (n % X)) % X; } int main() { long long n = 56789; cout
178 Views
Here we will see some hidden tricks of C++ related to STL.Assign value of pairs using braces ‘{}’. We can use them to assign into tuples also.pair my_pair = make_pair(10, 20); pair my_pair2 = { 10, 20 }; //using braces pair my_pair3 = { 10, { 'A', 20 } }; //complex pairSometimes we do not remember to include lots of headers, or sometimes we forget the names of the headers, in that time we can follow this trick to include all headers.#include C++ has inbuilt GCD function. That function is not so popular so we do not know about it. ... Read More
297 Views
In this section we will see some examples of code shortening strategy for competitive programming. Suppose we have to write some large amount of codes. In that code, we can follow some strategy to make them more short.We can change the type-name to make it short. Please check the code to get the ideaExample Code#include using namespace std; int main() { long long x = 10; long long y = 50; cout
234 Views
Suppose we have one integer variable whose size is 4 byte, another pointer variable is there, whose size is 8 bytes. So what will be the output of the following?Example#include using namespace std; main() { int a[4][5][6]; int x = 0; int* a1 = &x; int** a2 = &a1; int*** a3 = &a2; cout