Probability of Rain on N+1th Day in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:20:33

195 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 Getting More Value in Third Dice Throw in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:18:10

122 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

Program for Weighted Mean of Natural Numbers in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:16:26

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

Check Water Tank Overflow with Solid Balls in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:13:55

241 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

Check If an Array is Palindrome Using STL in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:12:04

2K+ Views

Given an array arr[n] of n integers, the task is to find whether array is a palindrome or not. We have to do the stated task using STL in C++.In C++ there is a feature of STL(Standard Template Library), it is a set of C++ template classes which are used to provide the data structures and several functions such as stacks, queues, lists, etc. To use these one must have knowledge of template classes.Palindrome is a sequence which is read the same from the front or rear of the sequence. Some simple examples of a palindrome are − MADAM, RACECAR, ... Read More

Check Whether a Number is a Buzz Number in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:07:45

1K+ Views

Given with a number ‘n’ and the task is to determine whether the given positive integer is a buzz number or not and display the result as an output.What is Buzz Number?For being a buzz number there are two conditions either of which must be true −Number should end with digit 7 e.g. 27, 657, etc.Number should be divisible by 7 e.g 63, 49, etc.Inputnumber: 49Outputit’s a buzz numberExplanation − since the number is divisible by 7 so it’s a buzz numberInputnumber: 29Outputit’s not a buzz numberExplanation − since the number is neither divisible by 7 nor end with digit ... Read More

Check If a Number Is Proth Number in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:05:54

849 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

Check Bitonicity of an Array in C++

Sunidhi Bansal
Updated on 13-Aug-2020 07:03:01

470 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

Average of an Array: Iterative and Recursive in C++

Sunidhi Bansal
Updated on 13-Aug-2020 06:59:49

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

Product of All Prime Nodes in a Singly Linked List in C++

Sunidhi Bansal
Updated on 13-Aug-2020 06:54:05

306 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

Advertisements