Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 45 of 81

Product of all prime nodes in a Singly Linked List in C++

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

Program for average of an array(Iterative and Recursive) in C++

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

Program to check bitnoicity of an array in C++

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

Given an array arr[N] of N integers, the task is to check whether the given array is bitonic or not. If the given array is bitonic then print “Yes its a bitonic array”, else print “No its not a bitonic array”.A Bitonic array is when the array is in strictly increasing order first and then in strictly decreasing order.Like this array arr[] = {1, 2, 3, 4, 2, -1, -5} is a bitonic array, because till 4 it is in strictly increasing order and after 4 it is in strictly decreasing order.Input arr[] = {1, 3, 5, 4, 2, 0}Output Yes its ...

Read More

Program to check whether a number is Proth number or not in C++

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

Given with a number ‘n’ and the task is to determine whether the given positive integer is a proth or not and display the result as an output.What is Proth Number?A proth number is given by$$N=k\cdot\:2^{n}+1$$Where, n is a positive integer and k is a odd positive integerThe first few proth numbers are given below −3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97.......Inputnumber: 17Outputits a proth numberInputnumber: 18Outputits not a proth numberApproach used in the given program is as followsInput the number to check for the conditionApply the given formula to check whether its a ...

Read More

Program to check if water tank overflows when n solid balls are dipped in the water tank in C++

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

Given with the radius and height of cylindrical water tank, ‘n’ number of spherical solid balls with the radius and the volume of water in the tank and the task is to check whether the tank will overflow or not when balls are dipped in the tank.Formula to calculate the volumeCylinder 3.14 * r * r * hWhere, r is radius of tank and h is the height of the tankSphere (4/3) * 3.14 * R * R * RWhere, R is radius of sphere ballInput tank_height = 5 tank_radius = 2 water_volume = 10 capacity = 10 ball_radius = 2Output It will overflowApproach ...

Read More

Program for weighted mean of natural numbers in C++

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

Given with an array of natural numbers and one more array containing the weights of the corresponding natural numbers and the task is to calculate the weighted mean of natural numbers.There is a formula which is used for calculating the weighted mean of natural numbers.$$\overline{x}=\frac{\displaystyle\sum\limits_{i=1}^n (x_{i*}w_{i})}{\displaystyle\sum\limits_{i=1}^n w_{i}}$$Where, x is the natural number and w is the weighted associated with that natural number.Input X[] = {11, 22, 43, 34, 25, 16} W[] = {12, 12, 43, 54, 75, 16}Output weighted mean is : 29.3019Explanation (11*12 + 22*12 + 43*43 + 34*54 + 25*75 + 16*16) / (12 + 12 + 43 + 54 +75 ...

Read More

Probability of getting more value in third dice throw in C++

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

Given three players A, B, C throwing dice, we have to find the probability of the C throwing the dice and the number scored by C is higher than both A and B.To check the probability of getting more value, we have to keep in mind that the value of the third dice throw is higher than the previous two.Like A thrown the dice and score 2 and B thrown the dice and scored 3 so the probability of C getting higher value is 3/6 = 1/2, because there are only 3 values which can be higher than the A ...

Read More

Probability of rain on N+1th day in C++

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

Given with an array containing 0’s and 1’s where 0’s represents no rain and 1’s represent rainy day. The task is to calculate the probability of rain on N+1th day.To calculate the probability of rain on N+1th day we can apply the formulaTotal number of rainy days in the set / total number of days in aInput arr[] = {1, 0, 0, 0, 1 }Output probability of rain on n+1th day : 0.4Explanation total number of rainy and non-rainy days are: 5 Total number of rainy days represented by 1 are: 2 Probability of rain on N+1th day is: 2 / 5 = ...

Read More

Probability of reaching a point with 2 or 3 steps at a time in C++

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

A person “A” is walking from a starting position X = 0, the task is to find the probability to reach exactly X = num, if he/she can either take 2 or 3 steps. Probability for step length 2 i.e. P, the probability for the step length 3 is 1 - P.Input num = 5, p = 0.2Output 0.32Explanation There can be 2 ways to reach num, i.e, 5 2+3 with probability 0.2 * 0.8 = 0.16 3+2 with probability 0.8 * 0.2 = 0.16 So, total probability will be 0.16 + 0.16 = 0.32Input num = 2, p = 0.1Output 0.1Approach used below is ...

Read More

Probability that the pieces of a broken stick form a n sided polygon in C++

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

We are given with the stick of any length and that stick can be broken randomly into n pieces which can be of type integer or floating point and the task is to find whether the broken pieces can form a n sided polygon.We can calculate the probability by applying the formula$$P(E^{\prime})=1-P(E)=1-\frac{n}{2^{n-1}}$$Where, n is the number of pieces generated by breaking the stick into parts.Input length = 10 , pieces = 4Output probability is : 0.5Explanation − given with length of size 10 cm and it is broken into 4 partsInput length = 5 , pieces = 3Output probability is : 0.25Explanation − given ...

Read More
Showing 441–450 of 809 articles
« Prev 1 43 44 45 46 47 81 Next »
Advertisements