Server Side Programming Articles

Page 1532 of 2109

Bitwise AND of N binary strings in C++

sudhir sharma
sudhir sharma
Updated on 03-Dec-2024 800 Views

In this problem, we are given an array bin[] of size n of binary strings. Our task is to create a program to find the Bitwise AND (&) of N binary strings. Here, we will take all numbers and find the bitwise AND of them i.e. bin[0] & bin[1] &... bin[n-2] & bin[n] Example Let’s take an example to understand the problem. Input − bin[] = {“1001”, “11001”, “010101”} Output − 000001 Explanation Bitwise AND of all binary strings − (1001) & (11001) & (010101) = 000001 To solve this problem, ...

Read More

Largest gap in an array in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 03-Dec-2024 379 Views

In this tutorial, we are going to write a program that finds the largest difference between the two elements in the given array. Approach Let's look at the approach we will follow to solve this problem. Firstly, we will initialize the array. Then we will find or search for the max and min elements in the array. And will return max - min. Example Here is the following code for finding the largest gap in an array in C++. #include using namespace std; ...

Read More

Structure vs class in C++

Nishtha Thakur
Nishtha Thakur
Updated on 03-Dec-2024 364 Views

In C++ the structure and class are basically the same. But there are some minor differences. These differences are like below. The class members are private by default, but members of structures are public. Let us see these two codes to see the differences. Example Code for Class Here is the following code for the class. #include using namespace std; class my_class {   public:  int x = 10; }; int main() {  my_class my_ob;  cout

Read More

C++ Program to Perform Complex Number Multiplication

Ankith Reddy
Ankith Reddy
Updated on 03-Dec-2024 7K+ Views

Complex numbers are numbers that are expressed as a+bi, where i is an imaginary number and a and b, are real numbers. Some examples of complex numbers are − 2+3i 5+9i 4+2i Example A program to perform complex number multiplication is as follows − #include using namespace std; int main(){  int x1, y1, x2, y2, x3, y3;  cout y1;  cout y2;  x3 = x1 * x2 - y1 * y2;  y3 = x1 * y2 + y1 * x2;  cout

Read More

Delete a node in a Doubly Linked List in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 03-Dec-2024 7K+ Views

In this tutorial, we are going to learn how to delete a node in the doubly linked list. Approach Let's see the steps to solve the problem. Write struct with data, prev, and next pointers. Write a function to insert the node into the doubly linked list. Initialize the doubly ...

Read More

Read whole ASCII file into C++ std::string

George John
George John
Updated on 03-Dec-2024 15K+ Views

This is a simple way to read whole ASCII file into std::string in C++ − Algorithm Here is the algorithm we will follow to Read the whole ASCII file into C++ std::string. Begin  Declare a file a.txt using file object f of ifstream type to perform a read operation.  Declare a variable str of string type.  If(f) Declare another variable ss of ostringstream type. Call rdbuf() function to read the data of the file object. Put the ...

Read More

Matrix Chain Multiplication (A O(N^3) Solution) in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 02-Dec-2024 4K+ Views

If a chain of matrices is given, we have to find a minimum number of correct sequences of matrices to multiply. We know that the matrix multiplication is associative, so for four matrices ABCD, we can multiply A(BCD), (AB)(CD), (ABC)D, and A(BC)D, in these sequences. Like these sequences, our task is to find which ordering is efficient to multiply.ExampleIn the given input there is an array say arr, which contains arr[] = {1, 2, 3, 4}. It means the matrices are of the order (1 x 2), (2 x 3), (3 x 4). Input − The ...

Read More

Program for Point of Intersection of Two Lines in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 02-Dec-2024 5K+ Views

Given points A and B corresponding to line AB and points P and Q corresponding to line PQ; the task is to find the point of intersection between these two lines. Note − The points are given in 2D plane on X and Y coordinates. Here A(a1, a2), B(b1, b2) and C(c1, c2), D(d1, d2) are the coordinates which are forming two distinct lines and P(p1, p2) is the point of intersection. (just for a diagrammatic explanation of the point of intersection) How to find the point of intersection − Let’s take the above figure as − Example So ...

Read More

Java program to merge contents of all the files in a directory

AmitDiwan
AmitDiwan
Updated on 20-Nov-2024 1K+ Views

In this article, we will learn how to merge the contents of all the text files in a directory into a single file using Java. It reads the data from each file and writes it into a new file while ensuring all data is stored in an organized manner. You’ll see how to handle files, read their content, and merge them programmatically. File class The java.io package contains the Java File class,  which provides an abstract representation of file and directory pathnames. It is commonly used for creating files and directories, searching for files, deleting files, and performing other file-related operations. File ...

Read More

Nested Classes in C++

Ankith Reddy
Ankith Reddy
Updated on 19-Nov-2024 30K+ Views

A nested class is a class that is declared in another class. The nested class is also a member variable of the enclosing class and has the same access rights as the other members. However, the member functions of the enclosing class have no special access to the members of a nested class. Syntax Here is the basic syntax defining and using nested classes in C++. class OuterClass { // Members of the outer classpublic: // Nested class definition class InnerClass { // Members of the inner class };}; Accessing Nested Classes To access a nested class from outside ...

Read More
Showing 15311–15320 of 21,090 articles
Advertisements