C++ Articles - Page 623 of 719

C++ Program to Find Transitive Closure of a Graph

Smita Kapse
Updated on 30-Jul-2019 22:30:25

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

Check if a given graph is Bipartite using DFS using C++

Anvi Jain
Updated on 30-Jul-2019 22:30:25

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

C++ Program to Create a Random Graph Using Random Edge Generation

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

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

C++ program to perform unique factorization of a Given Number

Nishu Kumari
Updated on 29-May-2025 19:24:54

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

How to compile 32-bit program on 64- bit gcc in C and C++

Anvi Jain
Updated on 30-Jul-2019 22:30:25

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

Is there any need of “long” data type in C and C++?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

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

Using return value of cin to take unknown number of inputs in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:25

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

fdim() in C++

Akansha Kumari
Updated on 10-Jun-2025 17:23:55

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

fmax() and fmin() in C++

Akansha Kumari
Updated on 02-Jun-2025 15:18:31

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

Constructor Delegation in C++

Anvi Jain
Updated on 30-Jul-2019 22:30:25

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

Advertisements