
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

709 Views
Suppose we have one undirected, connected tree where N nodes are present. These are labelled as 0...N-1 and N-1 edges are given. The ith edge connects nodes edges[i][0] and edges[i][1] together. We have to find a list where ans[i] is the sum of the distances between node i and all other nodes.So, if the input is like N = 6 and edges = [(0, 1), (0, 2), (2, 3), (2, 4), (2, 5)], then the output will be [8, 12, 6, 10, 10, 10]To solve this, we will follow these steps −Define a function dfs1(), this will take node, parent, ... Read More

1K+ Views
Suppose we have a positive integer N, we have to find how many different ways can we write it as a sum of consecutive positive integers?So, if the input is like 10, then the output will be 3, this is because we can represent 10 as 5 + 5 and 7 + 3, so there are two different ways.To solve this, we will follow these steps −ret := 1for initialize i := 2, (increase i by 1), do −sum := (i * (i + 1)) / 2if sum > N, then −Come out from the looprem := N - sumret ... Read More

957 Views
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

486 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

334 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

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

314 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

289 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

176 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

472 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