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 687 of 719
5K+ Views
The LU decomposition of a matrix produces a matrix as a product of its lower triangular matrix and upper triangular matrix. In the lower triangular matrix (L), all values above the main diagonal are zero, and in the upper triangular matrix (U), all values below the main diagonal are zero. In this article, we'll write a C++ program to perform LU decomposition of any matrix. Example Steps to perform LU Decomposition of Matrix LU Decomposition breaks a matrix A into two matrices L (lower triangular) and U (upper triangular) such that: A = L * U We ... Read More
827 Views
Shuffling an array means rearranging its elements in a random order. The Fisher-Yates algorithm creates a shuffle where every possible order is equally likely to happen. In this article, we'll show you how to write a C++ program that uses Fisher-Yates algorithm to shuffle an array. Fisher-Yates Algorithm to Shuffle an Array To shuffle an array, we use the Fisher-Yates algorithm. It works by swapping each element with another randomly selected element from the part of the array that we haven't shuffled yet. Here are the steps we follow: First, we start ... Read More
6K+ Views
The Greatest Common Divisor (GCD) of two numbers is the largest number that divides both of them. In this article we'll show you how to write a C++ program to find the GCD of two numbers using the recursive Euclid's algorithm. For example: Let's say we have two numbers that are 63 and 21. Input: 63 and 21 => 63 = 7 * 3 * 3 => 21 = 7 * 3 So, the GCD of 63 and 21 is 21. Output: 21 Finding GCD Using Recursive Euclid Algorithm The recursive Euclid algorithm helps us find ... Read More
6K+ Views
Any linear equation in one variable has the form aX + b = cX + d. Here the value of X is to be found, when the values of a, b, c, d are given. Let's understand this with an example: //Example 1 If the input equation is 2X + 4 = -9X + 14, the solution is: => 2X + 9x = 14 - 4 => 11X = 10 => X = 10 / 11 = 1.1 //Example 2 If the input equation is -3X + 5 = 4X - 9 the solution is: => -3X + ... Read More
29K+ Views
A queue is an abstract data structure that contains a collection of elements. Queue implements the FIFO mechanism i.e the element that is inserted first is also deleted first. In other words, the least recently added element is removed first in a queue.A program that implements the queue using linked list is given as follows −Example#include using namespace std; struct node { int data; struct node *next; }; struct node* front = NULL; struct node* rear = NULL; struct node* temp; void Insert() { int val; coutdata = val; front = rear; ... Read More
93K+ Views
A queue is a linear data structure that contains a collection of elements. Queue implements the FIFO mechanism i.e., the element that is inserted first is also deleted first. In other words, the least recently added element is removed first in a queue. Implementation Steps Based on the below implementation. Here are the steps to implement queue using array: Initialize Queue: Create an array queue[100] and set front and rear to -1 to indicate an empty queue. Predefine Input Values: Store input elements in input_values[] for insertion. ... Read More
371 Views
The atan2() function returns the tangent inverse of the coordinate in terms of y and x. Here y and x are the values of the y and x coordinates respectively. It is an inbuilt function in C++ STL.The syntax of the atan2() function is given as follows.atan2(dataType var1, dataType var2)As can be seen from the syntax, the function atan2() accepts two parameters var1 and var2 of data type float, double or long double that are y and x point respectively.The value returned by atan2() is in the range of -pi to pi and is the angle between the (x, y) ... Read More
1K+ Views
The acos() function returns the inverse cosine of an angle given in radians. It is an inbuilt function in C++ STL.The syntax of the acos() function is given as follows.acos(var)As can be seen from the syntax, the function acos() accepts a parameter var of data type float, double or long double. The value of this parameter should be between -1 and 1. It returns the inverse cosine of var in the range of -pi to pi.A program that demonstrates acos() in C++ is given as follows.Example Live Demo#include #include using namespace std; int main() { double d = ... Read More
175K+ Views
A stack is an abstract data structure that contains a collection of elements. Stack implements the LIFO mechanism i.e. the element that is pushed at the end is popped out first. Some of the principle operations in the stack are −Push - This adds a data value to the top of the stack.Pop - This removes the data value on top of the stackPeek - This returns the top data value of the stackA program that implements a stack using array is given as follows.Example#include using namespace std; int stack[100], n=100, top=-1; void push(int val) { if(top>=n-1) ... Read More
39K+ Views
A Doubly Linked List is a data structure made up of nodes created using self-referential structures. Each node contains three parts, namely the data, a pointer to the next node, and a pointer to the previous node. Also, the doubly linked list can be traversed in both forward and backward directions. Only the reference to the first node is required to access the whole linked list. This is known as the head. The last node in the list points to nothing, so it stores NULL in that part. In this article, we will write a C++ program to ... Read More