Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 311 of 719
2K+ Views
Given an array of N integers arr[N], the task is to find the average of arr[N]. To achieve the result we can either use iterative approach or the recursive approach. We will be showing both in the given solution.Average of an array will be sum of all the elements of an array divided by the number of elements.Iterative methodIn iterative approach, we use loops like for-loop, while-loop or do-while loop which executes the statements till the condition holds true which means 1.Let’s take an example and then discuss how it can be obtained using iterative approach.Input arr[] = {1, 2, 4, ... Read More
12K+ Views
In this problem, we are given two binary strings, and we need to find their sum and return the result as a binary string. A binary string is a string that contains only the characters '0' and '1', where 0 and 1 are binary numbers. While adding two binary numbers, we follow the binary addition rules given below - 1 + 0 = 1 0 + 1 = 1 0 + 0 = 0 1 + 1 = 0 with a carry of 1 ... Read More
315 Views
Given with n nodes and the task is to print the product of all the prime nodes in a linked list. Prime nodes are the ones that will have prime values as their count locations.Input 10 20 30 40 50Output 4, 00, 000Explanation − 10 is at index value 1 which is non-prime so it will be skipped. Moving to 20 with index value 2 which is a prime number so it will be considered. Similarly, 40 and 50 are at prime index locations.Product − 20*40*50 = 4, 00, 000In the above diagram, red coloured nodes represents the prime nodesApproach used below ... Read More
270 Views
Given with a binary tree containing nodes and the task is to find the product of all the nodes of a given binary tree.In a binary tree, there is a root node which is the master node of all the nodes in a tree. A node contains data part, left pointer which will further create left subdirectory and a right pointer which will help in creating right subdirectory. So to traverse the tree, we can take a temporary pointer that will associate with left pointer to traverse left subdirectory or right pointer to traverse the right sub directory.Input Output Nodes are-: 10, ... Read More
509 Views
Given with a binary tree containing nodes and the task is to find the product of all the leaf nodes of a given binary tree.Leaf nodes are the end nodes which don’t have any children. In a tree, a node can act as a parent node or child node except the root node which can only be a parent node. So the nodes with right and left pointer as NULL are the leaf nodes.Input Output Leaf nodes are -: 23, 34, 25 Product-: 23*34*25 = 19550ApproachInput the node dataTraverse all the nodes starting from the root node and going to either left ... Read More
146 Views
Given with the tree of nodes with data in a string format and the task is to find the product of the nodes at k-th level in a binary tree. Every node of a tree contains three things i.e. data part, left pointer for left subtree and right pointer for right subtree.Level of binary tree starts from number 0 and it can go till ‘n’ which can be any positive number. So, we are given with the level ‘k’ and program must calculate the product of the nodes at given ‘k’ level.In the binary tree, if let’s say we are ... Read More
138 Views
Given with two players let’s say A and B both are trying to get a penalty for winning the match. Given with four integer variables a, b, c, d so the probability of A getting the penalty first is a / b and probability of B getting the penalty first is c / d.The one who scores the penalty first will win the match and as per the given problem statement program must find the probability of A winning the match.Input a = 10, b = 20, c = 30, d = 40Output probability is 0.5333Inputa = 1, b = 2, c ... Read More
330 Views
Given with an array of size ’n’ and the task is to find the probability of the given element k if available in an array.Traverse the entire array till ‘n’ which is equals to the number of elements in an array and search for the given element or key ‘k’. If the element is present in an array than calculate its probability else print 0.Input arr[] = { 1, 2, 3, 4, 5, 6} K = 5Output probability of a key 5 in an array is :0.166Input arr[] = { 1, 2, 3, 4, 5, 6, 7 } K = 8Output probability of a ... Read More
174 Views
Given with two different arrays and the task is to find the probability of the random pair chosen to be the maximum weighted pair.A Pair will contain one element from let’s say array1 and another element form another array let’s say array2. So the program must find the probability of the pair that will contain first element to be the maximum element of array 1 and second element to be the maximum element of array 2 hence forming the maximum weighted pair.Input arr1[] = { 2, 23 } arr2[] = { 10, 3, 8 }Output probability of maximum pair : 0.166667Explanation set of ... Read More
2K+ Views
Function overloading is also known as method overloading. Function overloading is the feature provided by the concept of polymorphism which is widely used in object-oriented programming.To achieve function overloading, functions should satisfy these conditions −Return type of functions should be sameName of the functions should be sameParameters can be different in type but should be same in numberExampleint display(int a); int display(float a); // both the functions can be overloaded int display(int a); float display(float b); //both the functions can’t be overloaded as the return type of one function is different from anotherlet’s discuss the functions that can’t overloaded in ... Read More