Found 7346 Articles for C++

Form a Number Using Corner Digits of Powers

Eva Sharma
Updated on 10-Mar-2023 12:17:23

84 Views

What are Corner digits? The corner digits of a number refer to the rightmost and the leftmost digits. For example, the corner digits of 1234 are 1 and 4. The corner digits of a single-digit number will be the number twice. For example, the corner digits of 2 will be 2 and 2. Problem Statement For given two numbers, n, and x, form a number using the corner digits of all the powers of n from 1 and x, i.e., n1, n2....nx. Examples Input: n = 2, x = 4 Output: 22448816 Explanation 21 = 2. Corner digits = ... Read More

Decimal Equivalent of Gray Code and Its Inverse

Eva Sharma
Updated on 10-Mar-2023 12:08:16

987 Views

Gray code or reflected binary code is a form of a binary representation of numbers in which two consecutive numbers only differ by one bit. For example, the gray code of 1 is 001, while the gray code of 2 is 011. Gray code is usually used in error correction because it prevents some data errors that can happen in the usual binary representations while state changes. Gray code is also helpful in k-maps, communication, etc., because of its unique property. Prerequisite Study decimal, binary and gray code notations before reading further. Problem Statement 1 Given a decimal number n, ... Read More

Cube Free Numbers smaller than n

Eva Sharma
Updated on 10-Mar-2023 12:01:22

195 Views

Cube-free numbers are those numbers that have no cubic divisors. A cubic divisor refers to an integer that is a cube and divides the number with zero remainders. For example, 8 is a cubic divisor of 16 since 8 is a cube of 2 (2*2*2 = 8), and 8 divides 16 with the remainder of zero. Thus, 8 and 16 both are not cube-free numbers. Problem Statement Find all the cube-free numbers less than a given number, n. Example Let's understand the problem with an example. Let n = 15, Thus, we have to find all the numbers less than ... Read More

Square pyramidal number (Sum of Squares)

Eva Sharma
Updated on 10-Mar-2023 11:58:22

211 Views

A Square Pyramidal Number means the Sum of the Square of Natural Numbers. Natural Numbers include all the numbers from 1 to infinity. For example, the first 4 Square pyramidal numbers are 1, 5, 14, 30. For better perception, consider the fact: If we take spheres of numbers equal to the square pyramidal numbers, starting from one, and stack them in descending order, they create a pyramid. Problem Statement Given a number Sum. If Sum is the sum of the squares of first “n” natural numbers, return n, otherwise return false. Example 1 Input = 30 Output = 4 ... Read More

Locate unused structures and structure-members

Satish Kumar
Updated on 03-Mar-2023 15:12:51

676 Views

Structures in programming languages like C and C++ are a collection of related data fields, which can be accessed and manipulated as a single entity. They are often used to group related data items into a single variable, making it easier to manage and work with complex data structures. However, as code bases grow and evolve over time, it is not uncommon for structures and their members to become unused or redundant. These unused structures and members can clutter code and make it more difficult to understand, maintain, and update. In this article, we will discuss some ways to locate ... Read More

Corrupt stack problem in C, C++ program

Satish Kumar
Updated on 03-Mar-2023 15:05:25

2K+ Views

Introduction The corrupt stack problem is a common issue that programmers encounter while developing software in C and C++ programming languages. This problem can arise due to a wide range of reasons and can cause severe problems in functioning of program. In this article, we will explore corrupt stack problem in detail and look at some examples of how it occurs. What is a Stack in C and C++? Before we discuss corrupt stack problem, we need to understand what a stack is. In C and C++, a stack is a data structure that allows data to be stored and ... Read More

Reverse a Stack using Queue

Sonal Meenu Singh
Updated on 22-Feb-2023 12:33:50

1K+ Views

Introduction Both Queue and Stack are linear data structures and are used to store data. Stack uses the LIFO principle to insert and delete its elements. A Queue uses the FIFO principle. In this tutorial, we will learn how to reverse a stack using Queue. Reversing means the last element of the Stack comes to first place and so on. What is Stack? The stack in the data structure is inspired by the stack in real life. It uses LIFO (Last In First Out) logic, which means the element that enters last in the Stack will be removed first. In ... Read More

How to Manage Full Circular Queue Event in C++?

Sonal Meenu Singh
Updated on 22-Feb-2023 12:28:34

199 Views

Introduction Circular Queue is an improvement over a linear queue and it was introduced to address the memory wastage problem in the linear queue. A circular queue uses the FIFO principle for the insertion and removal of the elements from it. In this tutorial, we will discuss the operations of the circular queue and how to manage it. What is Circular Queue? A circular queue is another kind of queue in a data structure, whose front and rear ends are connected with each other. It is also known as Circular Buffer. Its operations are similar to the linear queue, so ... Read More

Extracting last element of a Priority Queue without traversing

Sonal Meenu Singh
Updated on 22-Feb-2023 11:55:01

1K+ Views

Introduction The Priority Queue in C++ is not similar to the normal Queue in the data structure, it has one difference: all its elements have priorities. We can extract its elements by traversing in the Queue. But, here in this tutorial, we are trying a method for extracting the last element of the Priority Queue without traversing. Let’s start… What is Priority Queue? In data structure, the abstract data type is the priority queue. It is a queue where all its elements have some associated priorities. All its elements are removed based on their priorities. Higher priority data are ... Read More

Basic Operations for Queue in Data Structure

Sonal Meenu Singh
Updated on 22-Feb-2023 11:23:18

624 Views

Queue is a collection of different data types and is an important part of data structure, following a particular order to insert and remove elements. In this tutorial, we will understand the basic operations of the queue. What is Queue in Data Structure? A Queue is a linear data structure that resembles a queue in real life. You all have been part of some queue in school, the billing counter, or any other place, where the one entered first will exit first in the queue. Similarly, a queue in data structure also follows the FIFO principle, which defines First In ... Read More

Advertisements