Found 33676 Articles for Programming

C++ Program to Perform Addition Operation Using Bitwise Operators

Tapas Kumar Ghosh
Updated on 30-Apr-2025 18:17:52

2K+ Views

Bitwise operators are used for representing binary integers, where the operator directly performs operations on the individual bits of integer values. To perform an addition operation using bitwise operators, use operators like AND, XOR, and NOT. The OR operator cannot perform addition on its own because, 1 | 1 results in 1, but we need 2 as the output. Therefore, you can use the other three operators to implement the logic of addition. You can see the tabular representation of biwise operators by taking binary bits as 0 and 1. ... Read More

C++ Program to Use rand and srand Functions

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

640 Views

Random numbers can be generated in C++ using the rand() function. The srand() function seeds the random number generator that is used by rand().A program that uses rand() and srand() is given as follows −Example Live Demo#include #include #include using namespace std; int main() {    srand(1);    for(int i=0; i

C++ Program to Sort Elements in Lexicographical Order (Dictionary Order)

Tapas Kumar Ghosh
Updated on 21-May-2025 17:28:52

2K+ Views

Lexicographical order denotes the way the words are ordered in a list, based on alphabetical order according to their alphabets. For example: List of words: Harry Adam Sam Lexicographical order of words: Adam Harry Sam Sorting String Based on Lexicographical Order To implement the string in lexicographical order, use the two different iterators: one to point at the current string, and the other to compare it with the next strings in the array. If the first iterator points to a string that is greater than the one pointed to by the second iterator, then we swap ... Read More

C++ Program to Add Complex Numbers by Passing Structure to a Function

Tapas Kumar Ghosh
Updated on 02-May-2025 15:25:14

865 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 of the example of complex numbers are 2 + 5i, 3 - 9i, 8 + 2i, etc. How to add complex number? Here, we will explain how to add two complex numbers. Let us assume we have two complex numbers, Z1 and Z2. // a and b are the real and imaginary parts of Z1 Z1 = a + bi // c and d are the real and imaginary parts of Z2 Z2 = c + ... Read More

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

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

802 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

Advertisements