Found 34494 Articles for Programming

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

George John
Updated on 25-Jun-2020 09:10:59

579 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.A program to add two distances in inch-feet using a structure in C++ is given as follows −Example Live Demo#include using namespace std; struct DistanceFI {    int feet;    int inch; }; int main() {    struct DistanceFI distance1, distance2, distance3;    cout

C++ Program to Implement Vector

Ankith Reddy
Updated on 25-Jun-2020 09:14:02

812 Views

A vector is a dynamic array that can resize itself if an element is inserted or deleted. The vector elements are contained in a contiguous storage and the container handles the storage automatically.A program that implements vectors is given as follows −Example#include #include #include #include using namespace std; int main() {    int ch, val;    vector vec;    cout

C++ Program to Implement Variable Length Array

Arjun Thakur
Updated on 25-Jun-2020 08:33:13

6K+ Views

Variable length arrays can have a size as required by the user i.e they can have a variable size.A program to implement variable length arrays in C++ is given as follows −Example Live Demo#include #include using namespace std; int main() {    int *array, size;    cout

C++ Program to Implement Parallel Array

Chandu yadav
Updated on 25-Jun-2020 08:34:31

4K+ 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.An example of parallel arrays is as follows −employee_name = { Harry, Sally, Mark, Frank, Judy } employee_salary = {10000, 5000, 20000, 12000, 5000}In the above example, the name and salary of 5 different employees is stored in 2 arrays.A program that demonstrates parallel arrays is given as follows −Example#include #include using namespace std; int main() {    int ... Read More

C++ Program to Convert Octal Number to Binary Number

George John
Updated on 25-Jun-2020 08:36:10

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 NumberOctal Number011011500101510110260101012A program that converts the octal numbers into binary is given as follows −Example Live Demo#include #include using namespace std; int OctalToBinary(int octalNum) {    int decimalNum = 0, binaryNum = 0, count = 0;    while(octalNum != 0) {       decimalNum += (octalNum%10) ... Read More

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

Ankith Reddy
Updated on 25-Jun-2020 08:37:00

703 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 NumberOctal Number010101200111711001311000020A program that converts the binary numbers into octal and the octal numbers into binary is given as follows −Example Live Demo#include #include using namespace std; int BinarytoOctal(int binaryNum) {    int octalNum = 0, decimalNum = 0, count = 0;    while(binaryNum != 0) { ... Read More

C++ Program to Perform LU Decomposition of any Matrix

Arjun Thakur
Updated on 25-Jun-2020 08:41:22

4K+ Views

The LU decomposition of a matrix produces a matrix as a product of its lower triangular matrix and upper triangular matrix. The LU in LU Decomposition of a matrix stands for Lower Upper.An example of LU Decomposition of a matrix is given below −Given matrix is: 1 1 0 2 1 3 3 1 1 The L matrix is: 1 0 0 2 -1 0 3 -2 -5 The U matrix is: 1 1 0 0 1 -3 0 0 1A program that performs LU Decomposition of a matrix is given below −Example#include using namespace std; void LUdecomposition(float a[10][10], float ... Read More

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

Chandu yadav
Updated on 25-Jun-2020 08:47:18

650 Views

Fisher-Yates algorithm generates a random permutation of the array elements i.e. it randomly shuffles all the elements of an array. All the permutations for the array are equally likely as the Fisher-Yates algorithm is unbiased.A program to implement the Fisher-Yates Algorithm for array shuffling in C++ is given as follows −Example#include #include using namespace std; int main() {    int n;    cout

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

George John
Updated on 25-Jun-2020 08:48:58

5K+ Views

The Greatest Common Divisor (GCD) of two numbers is the largest number that divides both of them.For example: Let’s say we have two numbers that are 63 and 21.63 = 7 * 3 * 3 21 = 7 * 3So, the GCD of 63 and 21 is 21.The recursive Euclid’s algorithm computes the GCD by using a pair of positive integers a and b and returning b and a%b till b is zero.A program to find the GCD of two numbers using recursive Euclid’s algorithm is given as follows −Example Live Demo#include using namespace std; int gcd(int a, int b) ... Read More

C++ Program to Perform Complex Number Multiplication

Ankith Reddy
Updated on 25-Jun-2020 08:49:58

5K+ 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 on complex numbers are −2+3i 5+9i 4+2iA program to perform complex number multiplication is as follows −Example Live Demo#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

Advertisements