Programming Articles

Page 1484 of 2547

C++ Program for Gnome Sort?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 589 Views

Here we will see how the gnome sort works. This is another sorting algorithm. In this approach if the list is already sorted it will take O(n) time. So best case time complexity is O(n). But average case and worst case complexity is O(n^2). Now let us see the algorithm to get the idea about this sorting technique.AlgorithmgnomeSort(arr, n)begin    index := 0    while index < n, do       if index is 0, then          index := index + 1       end if       if arr[index] >= arr[index -1], then ...

Read More

Area of a Circumscribed Circle of a Square in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 261 Views

In this problem, we will calculate the area of the circumscribed circle of a square when we are given the side of the square. Before we go further let’s revise the basic definitions to understand the concepts better.Square is a quadrilateral with all sides equal.The circumscribing circle is a circle touches all the vertices of a polygon.The area is the quantitative representation of the extent of any two-dimensional figure.To calculate the area of the circumscribed circle of a square. We need to find the relation between the parameter of the circle and the square.Now, as in the figure, all the ...

Read More

C++ Program for Largest K digit number divisible by X?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 218 Views

In this problem we will try to find largest K-digit number, that will be divisible by X. To do this task we will take the largest K digit number by this formula ((10^k) – 1). Then check whether the number is divisible by X or not, if not, we will get the exact number by using this formula.𝑚𝑎𝑥−(𝑚𝑎𝑥 𝑚𝑜𝑑 𝑋)One example is like a 5-digit number, that is divisible by 29. So the largest 5-digit number is 99999. This is not divisible by 29. Now by applying the formula we will get −99999−(99999 𝑚𝑜𝑑 29)=99999−7=99992The number 99992 is divisible by ...

Read More

C++ Floating Point Manipulation

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 2K+ Views

Numerical implementation of a decimal number is a float point number. In C++ programming language the size of a float is 32 bits. And there are some floating point manipulation functions that work on floating-point numbers. Here we have introduced some of the floating-point manipulation functions.fmod()The fmod() function operating on floats will return the remainder of the division of the passed arguments of the method.Example#include #include using namespace std; int main() {    float a, b, rem;    a = 23.4;    b = 4.1;    rem = fmod(a,b);    cout

Read More

Sort elements of the array that occurs in between multiples of K in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 213 Views

Suppose we have an array A, and another integer K. We have to sort the elements that are in between any two multiples of K. Suppose A is like [2, 13, 3, 1, 21, 7, 8, 13, 12], and K = 2. The output will be [2, 1, 3, 7, 13, 21, 8, 13, 12]. Here multiple of 2 are 2, 8 and 12, the elements in between 2 and 8 are 13, 3, 1, 21, 7, they will be sorted as 1, 3, 7, 13, 21, the elements between 8 and 12 is only 13, so that is already ...

Read More

C++ Program to Split the array and add the first part to the end?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 596 Views

Here we will see how to split an array, and add the first part after splitting at the end position. Suppose the array contents are {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. We want to cut this intro two parts. The first part is from index 0 to 3 (split size 4), and second part is rest. After adding the first part at the end, the array elements will be like this {4, 5, 6, 7, 8, 9, 0, 1, 2, 3}. To solve this problem, we will follow this algorithm.AlgorithmsplitArray(arr, n, k)begin    for i := ...

Read More

Print the number of set bits in each node of a Binary Tree in C++ Programming.

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 227 Views

Given the binary tree, the function will generate the binary values of the keys stored in the nodes and then return the number of set bits(1) in that binary equivalent.ExampleBinary tree having keys as: 10 3 211 140 162 100 and 146KeyBinary equivalentSet bits(output)101010230011221111010011514010001100316210100010310011001003146100100103Here we are using the function __builtin_popcountThe function prototype is as follows −int __builtin_popcount(unsigned int)It returns the numbers of set bits in an integer i.e. the number of ones in the binary representation of the integer.AlgorithmSTART Step 1 -> create a structure of a node as    struct Node       struct node *left, *right   ...

Read More

Print Levels of all nodes in a Binary Tree in C++ Programming.

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 354 Views

Given the binary tree, the task is to print the level associated with every key stored in a node starting from 1 to nIn the above tree, nodes are −10 at level 1 3 and 211 at level 2 140, 162, 100 and 146 at level 3Given the key the program must print the level of that particular key.ExampleInput: 10 3 211 140 162 100 146 Output:    level of 10 is 1    Level of 3 is 2    Level of 211 is 2    Level of 140 is 3    Level of 162 is 3    Level of ...

Read More

Print the nodes at odd levels of a tree in C++ Programming.

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 212 Views

Given the binary tree, the program must print the nodes at odd levels of a tree and the levels of a binary tree start from 1 to n.As nothing is mentioned one of the two approaches can be implemented i.e. recursion or iteration.Since we are using a recursive approach, the program will make a recursive call to a function that will be fetching the nodes at odd levels and returning them.In the above binary tree −Nodes at level 1: 10 Nodes at level 2: 3 and 211 Nodes at level 3: 140, 162, 100 and 146So, the nodes at level ...

Read More

Print root to leaf paths without using recursion in C++ Programming.

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 310 Views

Given the binary tree the program must find out the multiple paths from the root to a leaf which means all the paths should be printed but the challenge is to without using recursion.We will traverse the tree iteratively as the constraint is to do it without recursion. So to achieve this we can use an STL map that will store the root element and whenever the leaf node is identified through level order traversal it will print the path from root to leaf as there is a map pointer which is pointing to a root node.In the above tree, ...

Read More
Showing 14831–14840 of 25,466 articles
Advertisements