C++ Articles

Page 56 of 597

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

What are the differences between bitwise and logical AND operators in C/C++

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

As we know the bit-wise AND is represented as ‘&’ and the logical operator is represented as ‘&&’. There are some fundamental differences between them. These are as follows − bitwise AND operator The bitwise AND (&) operator performs a bit-by-bit AND operation between two integers. The bitwise AND operator works on integer, short int, long, unsigned int type data, and also returns that type of data. Here, Each bit should be 1 to give the result as 1, else it will result in 0, 1 & 1 = 11 & 0 = 00 & 1 = 00 & 0 ...

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

C++ program to return all Boundary Elements of a Matrix

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 28-Nov-2024 7K+ Views

boundary elements of a matrix The boundary elements of a matrix are those elements that lie along its edges. A matrix is a two-dimensional array that can be of any given size. The boundary elements are those present on the edges of the matrix. Problem Description We are given a matrix of size m × n. We need to find the boundary elements of the matrix. Boundary elements are the elements present on the top and bottom rows and the first and last columns of the matrix. Below are examples to understand the boundary traversal of a matrix: ...

Read More

C++ Program to Return Quadrants in which a given Coordinates Lies

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 28-Nov-2024 7K+ Views

Cartesian-coordinate System and Quadrants The cartesian-coordinate system is divided into four Quadrants: Quadrant I, Quadrant II, Quadrant III, and Quadrant IV. In this article, we are going to learn how we can determine the quadrant in which given points i.e., x and y, lie. Problem Description We are given the position of a point (x, y), and we have to determine in which quadrant this point lies. Example Input: (-3, 2) Output: Quadrant II Input: (2, 5) Output: Quadrant I Input: (2, -4) Output: Quadrant IV Input: (-6, -3) Output: Quadrant III Using Conditional Quadrant Identification Approach ...

Read More

Parallelogram Star Pattern using C++

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 28-Nov-2024 10K+ Views

When we start learning to code, practicing star patterns is one of the best ways to improve logic building. One of the engaging patterns is the parallelogram pattern. In this article, we are going to learn how to print a Parallelogram Star Pattern using C++. What is Parallelogram Pattern? A parallelogram pattern is a geometrical arrangement of stars in a parallelogram shape. The stars are printed in such a manner that if we draw a closed figure on the boundary of the printed pattern, it will resemble a parallelogram. Each row is shifted with space, which creates a diagonal ...

Read More

C++ Program for Sum of Infinite Terms in GP

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 21-Nov-2024 9K+ Views

What is Geometric Progression (GP)? Geometric Progression (GP) is a sequence of numbers where each term is generated by multiplying the previous term by a constant value. This constant value in GP is known as the common ratio. In this article, we are going to discuss how to calculate the sum of infinite terms in a GP using different approaches in C++. Note: The important condition to remember is that a positive valid sum of infinite GP is only possible if the absolute of the common value (r) is less than 1, i.e., ∣r∣ < 1. Methods to Calculate ...

Read More
Showing 551–560 of 5,961 articles
« Prev 1 54 55 56 57 58 597 Next »
Advertisements