Found 7197 Articles for C++

C++ Program to Add Two Distances (in inch-feet) System Using Structures

Tapas Kumar Ghosh
Updated on 21-May-2025 17:29:39

798 Views

A structure is a collection of items of different data types. It is very useful in creating complex data structures with different data type records. A structure is defined with the struct keyword. An example of a structure is as follows: struct DistanceFI { int feet; int inch; }; The above structure defines a distance in the form of feet and inches. Example of Adding Two Distances (inch-feet) Using Structure The program uses a structure named DistanceFI to represent a distance in terms of feet and inches. It creates two different ... Read More

C++ Program to Implement Variable Length Array

Tapas Kumar Ghosh
Updated on 09-Apr-2025 19:05:12

7K+ Views

Variable length arrays can have a size as required by the user i.e they can have a variable size. A Variable−Length Array (VLA) is an array whose length is determined at runtime (not compile-time). Variable Length Array Using Vector A vector is defined by the resizable array that is part of data structures and is used to store multiple elements from the same data type. A variable length array can be created using the Vector. Syntax Following are the syntaxes that uses to modify the size dynamically using vector − // inserting the array element push_back() and, // ... Read More

C++ Program to Implement Parallel Array

Tapas Kumar Ghosh
Updated on 09-Apr-2025 19:02:54

5K+ Views

A parallel array is a structure that contains multiple arrays. Each of these arrays are of the same size and the array elements are related to each other. All the elements in a parallel array represent a common entity. Here, we provide the basic example to understand the parallel array in C++ − employee_name = { Harry, Sally, Mark, Frank, Judy } employee_salary = {10000, 5000, 20000, 12000, 5000} Here, The name and salary of 5 different employees is stored in two different arrays. Example of Parallel Arrays This is an implementation of a parallel array ... Read More

C++ Program to Convert Octal Number to Binary Number

Tapas Kumar Ghosh
Updated on 11-Apr-2025 18:14:50

1K+ Views

In a computer system, the binary number is expressed in the binary numeral system while the octal number is in the octal numeral system. The binary number is in base 2 while the octal number is in base 8. Here, we provide the tabular data to understand binary numbers and their corresponding octal numbers as follows: Octal Number ... Read More

C++ Program to Convert Binary Number to Octal and vice-versa

Nishu Kumari
Updated on 21-May-2025 09:48:14

1K+ Views

In a computer system, the binary number is expressed in the binary numeral system while the octal number is in the octal numeral system. The binary number is in base 2 while the octal number is in base 8. Examples of binary numbers and their corresponding octal numbers are as follows: Binary Number ... Read More

C++ Program to Perform LU Decomposition of any Matrix

Nishu Kumari
Updated on 30-May-2025 18:02:25

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

C++ Program to Implement Fisher-Yates Algorithm for Array Shuffling

Nishu Kumari
Updated on 30-May-2025 18:02:00

813 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

C++ Program to Find GCD of Two Numbers Using Recursive Euclid Algorithm

Nishu Kumari
Updated on 18-Aug-2025 18:44:02

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

C++ Program to Solve any Linear Equation in One Variable

Nishu Kumari
Updated on 22-May-2025 19:13:53

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

C++ Program to Implement Queue using Linked List

Chandu yadav
Updated on 25-Jun-2020 09:00:06

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

Advertisements