Programming Articles - Page 1922 of 3368

Program to find the common ratio of three numbers in C++

Revathi Satya
Updated on 22-May-2024 11:52:10

489 Views

In this article, Our task is to create a Program to find the common ratio of three numbers in C++. The common ratio of three numbers is usually the same ratio between two numbers multiplied by each other to get the next one. When a particular number of terms in progression or sequence are involved such as in the geometric progression, a common ratio can be easily found by dividing the term with the preceding term. For instance, if we have three numbers x, y, and z. then the common ratio r can be found as r = x:y = ... Read More

Program to find the diameter, cycles and edges of a Wheel Graph in C++

Ayush Gupta
Updated on 16-Sep-2020 08:55:31

340 Views

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

Program to find the Circumcircle of any regular polygon in C++

Ayush Gupta
Updated on 16-May-2022 07:22:35

203 Views

In this problem, we are given two numbers that give the number of sides of a polygon N and the length of each side A. Our task is to create a Program to find the Circumcircle of any regular polygon in C++.Problem description − Here, we need to find the radius and area of the circumcircle of the regular polygon whose side number and length are given.Let’s take an example to understand the problem, Inputn = 4 a = 2Program to illustrate the working of our solution, Example Live Demo#include using namespace std; void CalcRadAreaCircumcircle(float n, float a) {   ... Read More

Minimum Insertion Steps to Make a String Palindrome in C++

Arnab Chakraborty
Updated on 02-Jun-2020 11:36:26

318 Views

Suppose we have a string s, we have to make this string palindrome. in each step we can insert any character at any position, we have to find minimum number of characters that require to make this palindrome. If the string is like “mad”, then the answer will be 2 as we can add “da” before “mad”, or “am” after “mad” to make this palindrome.To solve this, we will follow these steps −Define a function lcs(), this will take s, x := sn := size of sreverse the string xs := concatenate space before s, x := concatenate space before ... Read More

Program to find the count of coins of each type from the given ratio in C++

Ayush Gupta
Updated on 16-Sep-2020 08:57:48

291 Views

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

Minimum Number of Flips to Convert Binary Matrix to Zero Matrix in C++

Arnab Chakraborty
Updated on 02-Jun-2020 11:33:59

179 Views

Suppose we have a m x n binary matrix mat. In one step, we can choose one cell and flip its bit and all the four neighbors of it if they are present. We have to find the minimum number of steps required to convert mat to a zero matrix. If there is no solution, then return -1.So if the given input is like [[0, 0], [0, 1]], alteration will be like −So we need 3 steps, the output will be 3.To solve this, we will follow these steps −n := number of rows, m := number of columns, x ... Read More

Program to find the Centroid of the Triangle in C++

Ayush Gupta
Updated on 16-Sep-2020 08:59:03

478 Views

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

Program to find the Break Even Point in C++

Ayush Gupta
Updated on 16-Sep-2020 09:00:07

261 Views

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

Palindrome Partitioning III in C++

Arnab Chakraborty
Updated on 02-Jun-2020 11:30:53

227 Views

Suppose we have a string s that is containing lowercase letters and an integer k. We have to maintain some properties. These are −First, we have to change some characters (if needed) of s to other lowercase English letters.Then divide the string s into k substrings such that each substring is a palindrome.We have to find the minimal number of characters that we need to change to divide the string.So if the string is like “ababbc” and k = 2, then the answer will be 1, as we have to change one character to split this into two palindrome strings. ... Read More

Program to find the Area of a Pentagon in C++

Ayush Gupta
Updated on 16-May-2022 07:23:40

661 Views

In this problem, we are given a number n that denotes that side of the pentagon. Our task is to create a program to find the Area of a Pentagon in C++.Pentagon is a five-sided geometric figure.Regular pentagon is a pentagon with all five sides and angles equal.Let’s take an example to understand the problem,Inputa = 7Output84.3Program to illustrate the working of our solution,Example Live Demo#include using namespace std; float calcpentagonArea(int a){    return ( ((6.8819)*a*a)/4); } int main() {    int a = 7;    cout

Advertisements