Programming Articles - Page 1922 of 3366

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

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

210 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

322 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

297 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

182 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

482 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

267 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

233 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

667 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

Race Car in C++

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

1K+ Views

Suppose we have a car, that starts at position 0 and speed +1 on an infinite number line. The car runs automatically according to a sequence of instructions A: for accelerate and R − for reverse. When we get an instruction "A", our car does the following −position := position + speed, then speed = speed * 2.When we get an instruction "R", our car does the following −if speed is positive then speed = -1, otherwise speed = 1.For example, after executing the instructions "AAR", our car goes to positions 0->1->3->3, and speed goes to 1->2->4->-1.Now suppose we have ... Read More

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

Ayush Gupta
Updated on 16-Sep-2020 09:03:01

447 Views

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

Advertisements