Server Side Programming Articles

Page 1464 of 2109

Sum of squares of binomial coefficients in C++

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

The binomial coefficient is a quotation found in a binary theorem which can be arranged in a form of pascal triangle it is a combination of numbers which is equal to nCr where r is selected from a set of n items which shows the following formulanCr=n! / r!(n-r)! or nCr=n(n-1)(n-2).....(n-r+1) / r!The sum of the square of Binomial Coefficient i.e (nC0)2 + (nC1)2 + (nC2)2 + (nC3)2 + ……… + (nCn-2)2 + (nCn-1)2 + (nCn)2Input :n=5 Output:252ExplanationIn this program first we have to find the binomial coefficient of r which is selected from n set then we have to ...

Read More

Sum of squares of Fibonacci numbers in C++

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

Fibonacci series is a mathematical sequence of number which starts from 0 and the sum of two numbers is equal to the next upcoming number, for example, the first number is 0 and the second number is 1 sum of 0 and 1 will be 1F0=0, F1=1AndFn=Fn-1+Fn-2, F2=F0+F1 F2=0+1 F2=1then when we add number 1 and 1 then the next number will be 2F1=1, F2=1AndFn=Fn-1+Fn-2, F3=F1+F2 F3=1+1 F3=2Fibonacci sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …We have to find the square of the fuel energy series and then we have to sum it and find ...

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 232 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 359 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 root to leaf paths without using recursion in C++ Programming.

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 311 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

Print the first shortest root to leaf path in a Binary Tree in C++ Programming.

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

Given the binary tree the program must find out the shortest path from the root to leaf amongst many given paths.Since we traverse the tree from left to right, so if there are multiple shortest paths from the root to leaf than the program will print the first traversed the shortest path on the left side of a tree.We can use a queue that will traverse each level using Level order traversal and the path with the least number of levels will be printed as it will be the shortest path from the root to leafIn the above tree, multiple ...

Read More

Print path between any two nodes in a Binary Tree in C++ Programming.

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

We are given with a binary tree of distinct nodes and two nodes of the binary tree whose path in the binary tree we want to print.For Example − We want to print the path between node 140 to 211 so its output should be like −Output: 140->3->10->211The idea is to find paths form root nodes to the two nodes and store them in two separate vectors or arrays say path1 and path2.Now, there arise two different cases −If the two nodes are in different subtrees of root nodes − When the two nodes are in different subtrees like one ...

Read More

Print the nodes of binary tree as they become the leaf node in C++ Programming.

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

Given a binary tree, we have to print its leaf nodes and then we have to remove those leaf nodes and then repeat till there are no nodes left in the tree.ExampleSo the output of the problem should be −6 7 9 13 14 3 4 2 1ApproachWe have adopted an approach where we are applying DFS.For applying a temporary value zero is assigned to every value and then assign all the nodes with the value maximum(value of both child)+1.AlgorithmSTART STEP 1-> DEFINE A struct Node    WITH DATA MEMBERS data, order, *left, *right STEP 2-> DEFINE A struct Node* ...

Read More

Adding elements of an array until every element becomes greater than or equal to k in C++.

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

Array − An array is a container of elements of the same data type, whose elements are 0 indexed.In this problem, we will use an array of integers. And check if all the elements are greater than the given number or not. Here we will check if all elements of the array are greater than or equal to a given number k. If not then we will add two minimum elements of the array and treat this sum as a single element. And then again check for the same condition for the new array. If the condition comes out to ...

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
Showing 14631–14640 of 21,090 articles
Advertisements