Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 65 of 81

C++ Program to check if tank will overflow, underflow or filled in given time

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

Given with the rate of filling the tank, height of a tank and radius of a tank and the task is to check whether the tank is overflow, underflow and filled in given time.ExampleInput-: radius = 2, height = 5, rate = 10 Output-: tank overflow Input-: radius = 5, height = 10, rate = 10 Output-: tank undeflowApproach used below is as follows −Input the rate of filling time, height and radius of a tankCalculate the volume of a tank to find the original rate of flow of water.Check for the conditions to determine the resultIf expected < original ...

Read More

C++ Program for sum of arithmetic series

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 4K+ Views

Given with ‘a’(first term), ‘d’(common difference) and ‘n’ (number of values in a string) and the task is to generate the series and thereby calculating their sum.What is an Arithmetic seriesArithmetic series is the sequence of numbers with common difference where the first term of a series is fixed which is ‘a’ and the common difference between them is ‘d’.It is represented as −a, a + d, a + 2d, a + 3d, . . .ExampleInput-: a = 1.5, d = 0.5, n=10 Output-: sum of series A.P is : 37.5 Input : a = 2.5, d = 1.5, n ...

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 217 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 345 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 204 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 300 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 284 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 535 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 215 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

Program for Celsius To Fahrenheit conversion in C++

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

Given with temperature ‘n’ in Celsius the challenge is to convert the given temperature to Fahrenheit and display it.ExampleInput 1-: 100.00    Output -: 212.00 Input 2-: -40    Output-: -40For converting the temperature from Celsius to Fahrenheit there is a formula which is given belowT(°F) = T(°C) × 9/5 + 32Where, T(°C) is temperature in Celsius and T(°F) is temperature in FahrenheitApproach used below is as followsInput temperature in a float variable let’s say CelsiusApply the formula to convert the temperature into FahrenheitPrint FahrenheitALGORITHMStart Step 1 -> Declare a function to convert Celsius to Fahrenheit    void cal(float cel) ...

Read More
Showing 641–650 of 809 articles
« Prev 1 63 64 65 66 67 81 Next »
Advertisements