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 623 of 719
531 Views
If a directed graph is given, determine if a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given graph. Reachable mean that there is a path from vertex i to j. This reachability matrix is called transitive closure of a graph. Warshall algorithm is commonly used to find the Transitive Closure of a Given Graph G. Here is a C++ program to implement this algorithm.AlgorithmBegin 1. Take maximum number of nodes as input. 2. For Label the nodes as a, b, c….. 3. To check if there any edge ... Read More
219 Views
A bipartite graph is a graph in which if the graph coloring is possible using two colors only i.e.; vertices in a set are colored with the same color. This is a C++ program to check whether a graph bipartite or not using DFS.AlgorithmBegin An array color[] is used to stores 0 or 1 for every node which denotes opposite colors. Call function DFS from any node. If the node w has not been visited previously, then assign ! color[v] to color[w] and call DFS again to visit nodes connected to w. If ... Read More
1K+ Views
In this program a random graph is generated for random vertices and edges. The time complexity of this program is O(v * e). Where v is the number of vertices and e is the number of edges.AlgorithmBegin Develop a function GenRandomGraphs(), with ‘e’ as the number of edges and ‘v’ as the number of vertexes, in the argument list. Assign random values to the number of vertex and edges of the graph, using rand() function. Print the connections of each vertex, irrespective of the direction. ... Read More
213 Views
Here is a C++ Program to get all the unique factorization of a given integer such that addition of a partition results an integer. In this program, a positive integer n is given, and we shall generate all possible unique ways to represent n as sum of positive integers. Algorithm to Perform Unique Factorization Below is the algorithm to perform the unique factorization of a given number: Begin function displayAllUniqueParts(int m): 1) Set Index of last element k in a partition to 0 ... Read More
3K+ Views
Nowadays the compiler comes with default 64-bit version. Sometimes we need to compile and execute a code into some 32bit system. In that time, we have to use this feature.At first, we have to check the current target version of the gcc compiler. To check this, we have to type this command.gcc –v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu ........... ........... ...........Here it is showing that Target is x86_64. So we are using the 64-bit version of gcc. Now to use the 32-bit system, we have to write the following command.gcc –m32 program_name.cSometimes this command may generate ... Read More
187 Views
In C or C++, there are four different datatypes, that are used for integer type data. These four datatypes are short, int, long and long long. Each of these datatypes takes different memory spaces. The size varies in different architecture and different operating systems. Sometimes int takes 4-bytes or sometimes it takes 2-bytes. This also happen for the compilers. So we can use cross compilers.The cross compilers are basically a compiler, which is capable of compiling for a platform other than current platform.So if we want to compile the following code in 32bit system, and 64-bit system, it will generate ... Read More
1K+ Views
Sometimes we need variable number of inputs in our program. In this program we will see how to use cin to take variable number of inputs.The simple solution is run a loop, and when one specific value is pressed, it stops. The another idea is using the cin >> input. This will return false when value is non-numeric.Example#include using namespace std; main() { int input; int n = 0; cout > input) n++; cout
226 Views
C++ fdim() Function The fdim() function returns the positive difference between two floating-point values. For example, if we have two arguments, a and b, respectively, then it will return a-b if a > b, else it will return 0. This function is defined under or header files and supports float, double, and long double overloads. Syntax Here is the following syntax for fdim() function in C++. In the following syntax, data_type defines the type of data it will take as input and return. data_type fdim(data_type value_1, data_type value_2); Parameters This method accepts two parameters of floating type (i.e., can ... Read More
596 Views
The fmax() and fmin() functions in C++ are used to check the maximum or minimum of two floating-point numbers. These functions are defined under the header file of the C++ standard library. C++ fmax() function The fmax() is used to compare and return the larger of two floating-point values. These floating point values can be float, double, and long double. Syntax data_type fmax(data_type value_1, data_type value_2); Here, data_type could be float, double and long double. C++ fmin() function The fmin() is used to compare and return the smaller of two floating-point values. These floating point values can be float, ... Read More
1K+ Views
Here we will see what is the constructor delegation? When a constructor calls other constructor of the same class, then it is called the constructor delegation. This feature is present from C++11.Let us see the following program, and try to analyze what are the difficulties in this code.Example#include using namespace std; class MyClass { int a, b, c; public: MyClass(){ a = b = c = 0; } MyClass(int c) { // Initializing a and b are redundent, only c initialization is needed here a = 0; b = 0; this->c = c; } void display(){ cout