We are required to write a JavaScript function that takes in a number and checks whether it falls in Fibonacci series or not. We should return a boolean.Following is the code to check for Fibonacci −Exampleconst num = 89; const isFib = query => { if(query === 0 || query === 1){ return true; } let prev = 1; let count = 2; let temp = 0; while(count
In this problem, we are given two values that denote the base and height of a parallelogram. Our task is to create a Program to find the Area of a Parallelogram in C++.Parallelogram is a four side closed figure that has opposite sides equal and parallel to each other.Let’s take an example to understand the problem, InputB = 20, H = 15Output300ExplanationArea of parallelogram = B * H = 20 * 15 = 300Solution ApproachTo solve the problem, we will use the geometrical formula for area of parallelogram, Area = base * height.Program to illustrate the working of our solution, ... Read More
In this problem, we are given the three variables that denote total monthly expenditure (E), selling price (S) of the product, overhead maintenance (M) on each product. Our task is to create a program to find the Break Even Point in C++.Break-Even Point is the total number of products that are required to be sold so that there should not be any loss or profit for the seller.Problem Description − We need to find the total no. of products to be sold to make sure there is no loss.Let’s take an example to understand the problem, InputE = 2400, S ... Read More
In this problem, we are given a 2D array that denotes coordinates of three vertices of the triangle. Our task is to create a program to find the Centroid of the Triangle in C++.Centroid of a triangle is the point at which the three medians of the triangles intersect.Median of a triangle is the line that connects the vertex of the triangle with the center point of the line opposite to it.Let’s take an example to understand the problem, Input(-3, 1), (1.5, 0), (-3, -4)Output(-3.5, -1)ExplanationCentroid (x, y) = ((-3+2.5-3)/3, (1 + 0 - 4)/3) = (-3.5, -1)Solution ApproachFor solving ... Read More
In this problem, we are given four numbers that define the totalPrice and the ratio of coins of 1 Rs, 50 paise, 25 paise in the bag. Our task is to create a program to find the count of coins of each type from the given ratio in C++.Code description − Here, we need to use the coins of 1 Rs, 50 paise, and 25 paise from the bag to give the total sum of coins to the given total.Let’s take an example to understand the problem, InputTotalPrice = 225, 1Rs = 2, 50P = 3, 25P = 4Output1 Rs ... Read More
In this problem, we are given a number that denotes the number of vertices of a Wheel Graph. Our task is to create a Program to find the diameter, cycles and edges of a Wheel Graph in C++.Problem description − Here, we need to find the number of cycles, number of edges, and the diameter of Wheel Graph with n vertices.First, let’s understand some basics about Wheel Graph −A wheel graph is obtained from a cycle graph Cn-1 by adding a new vertex. That new vertex is called a Hub which is connected to all the vertices of Cn.Example of ... Read More
In this problem, we are given two numbers that define the marked price(M) and selling price(S) of a certain product. Our task is to create a program to find the Discount Percentage in C++.Discount is the amount that is deducted from the actual price (marked price) on a product.The formula for discount is, discount = marked price - selling priceDiscount percentage is the percentage of the price that is deducted from the actual price of the product.The formula for discount percentage is, discount percentage = (discount / marked price ) * 100Let’s take an example to understand the problem, Input240, ... Read More
In this problem, we are given two points A and B, starting and ending point of a line. Our task is to create a program to find the mid-point of a line in C++.Problem Description − Here, we have a line with starting and ending points A(x1, y1) and B(x2, y2). And we need to find the mid-point of the line.Let’s take an example to understand the problem, Inputa(x1, y1) = (4, -5) b(x2, y2) = (-2, 6)Output(1, 0.5)Explanation(x1 + x2)/2 = 4 - 2 / 2 = 1 (y1 + y2)/2 = -5 + 6 / 2 = 0.5Solution ... Read More
In this problem, we are given two integers that give the head start that is given by A to B and C respectively in a 100-meter race. Our task is to create a program to find the head start in a race in C++.Code Description − Here, there are head starts that are given by A to B and A to C respectively in a 100-meter race. We need to find the relative head start that is given by B to C in the 100-meter race.Let’s take an example to understand the problem, Input20, 28Output90ExplanationA gives B a head-start of ... Read More
In this problem, we are an array arr[] consisting of n integer values. Our task is to create a Program to find the Hidden Number in C++.Code description − For an array, the hidden number, is the number which when subtracted from each element of the array gives the sum 0.Let’s take an example to understand the problem, Inputarr[] = {4, 1, 6, 7, 2}Output4Subtracting 4 from all elements of the array. And adding of values= (1 - 4) + (6 - 4) + (7 - 4) + (4 - 2) = -3 + 2 + 3 - 2 = ... Read More