Found 7346 Articles for C++

C++ Program to calculate the volume and area of the Cylinder

Arnab Chakraborty
Updated on 17-Oct-2022 12:39:52

6K+ Views

The cylinder is a tube-like 3D object whose base is a circle and has a certain height. The volume of a cylinder is actually how much space it is taking in the space. In this article, we shall cover a few techniques to calculate the volume and the surface area of a cylinder in C++. A cylinder has two basic parameters. The height β„Ž and the radius of its bases π‘Ÿ. The surface area of a cylinder can have two variations. Only the outer curved surface (for hollow and both side open cylinder) and area with the curved surface with ... Read More

C++ Program to calculate the volume of Cube

Arnab Chakraborty
Updated on 17-Oct-2022 12:34:48

3K+ Views

Cubes are the basic 3D objects which have 8 vertices, 12-edges, and 6-faces. The volume of a 3D object is how much space it is occupying in the world. In this article, we will see how we can calculate the volume of a cube by writing a C++ program. A cube has all edges of equal length. The area for each face is π‘˜2 where π‘˜ is the length of each side. As 3D objects have length, breadth, and width, so the volume of it will be π‘˜3. Let us see the algorithm and corresponding C++ implementation to find the ... Read More

C++ Program to calculate the sum of all odd numbers up to N

Arnab Chakraborty
Updated on 17-Oct-2022 12:27:52

10K+ Views

Getting series sum is one of the simplest practicing tasks while we are learning programming and logic build up. In mathematics, there are certain ways to find sum of series present in different progressions. In programming, we generate them one by one by implementing the logics, and repeatedly add them to get the sum otherwise perform any other operation if needed. In this article we shall cover techniques to get sum of all odd numbers up to N using C++. There are two possible ways to get this sum with a little variation. Let us see these approaches one by ... Read More

C++ Program to Print the Multiplication Table in Triangular Form

Arnab Chakraborty
Updated on 17-Oct-2022 12:24:43

526 Views

To memorise the few fundamental multiplication results in tabular or graphic form, use multiplication tables. This article will cover how to produce a multiplication table in C++ that looks like a right-angled triangle. In a select few situations where a larger number of results may be easily memorised, triangular representation is effective. In this format, a table is shown row by row and column by column, with each row containing only the entries that fill that column. To solve this problem, we need basic looping statements in C++. For displaying the numbers in triangular fashion, we need nested looping to ... Read More

C++ Program to Get Input from the User

Arnab Chakraborty
Updated on 04-Apr-2023 14:14:55

946 Views

While writing a program in any language, taking input is a fundamental job that we do in almost all programs. Sometimes we take input directly from the console or take the inputs from the files. Taking inputs from the files is somewhat beneficial because it does not require us to type inputs again and again, or sometimes we can save some good input test cases into a file. However, in this article, we are going to focus on console-based inputs. We will learn different techniques to get inputs from the user in C++. There are a few different approaches to ... Read More

C++ Program to Round a Number to n Decimal Places

Arnab Chakraborty
Updated on 17-Oct-2022 12:11:09

18K+ Views

Representing numbers in outputs is an interesting and also important task while we are writing programs in any language. For integer type (short, long, or medium) type data, it is easy to express the numbers as output. For floating point numbers (float or double type), sometimes we need to round them off to certain decimal places. For example, if we want to represent 52.24568 up to three decimal places, some pre-processing needs to be done. In this article, we shall cover a few techniques to represent a floating-point number up to a certain decimal placed by rounding it off. Among ... Read More

C++ Program to Calculate simple interest and compound interest

Arnab Chakraborty
Updated on 17-Oct-2022 09:22:53

18K+ Views

After calculating interest on the principal amount, simple interest is calculated by taking the principal amount, the rate of interest, and the number of years it will take to calculate interest. The formula is quite easy to understand. The power law is used to calculate compound interest by taking into account the principal amount, the rate of interest, and the period. Here, the formula is likewise not difficult. In this article, we'll talk about how to calculate simple and compound interest values and then use the C++ programming language to put this logic into practice. Simple Interest Simple interest is ... Read More

Finding the second largest element in BST using C++

Prateek Jangid
Updated on 10-Aug-2022 12:03:40

568 Views

In a binary search tree (BST), the second largest element must be returned. In a binary tree, the second element is the largest element. According to the given BST, 13 is the second largest element. Now we are using the C++ approach to solve this problem. We can traverse the tree inorder, and by observation, we can observe that the second largest element in the given BST is 13. The inorder of the tree will be 1 3 4 6 7 8 10 13 14, and we can observe that the elements are in the sorted array. So we ... Read More

C++ program to find the shortest distance between two nodes in BST

Prateek Jangid
Updated on 10-Aug-2022 12:02:23

665 Views

In this article, we are given a BST (binary search tree), and we need to find the shortest distance between 2 given nodes in the BST. Let's have a tree and below are the following scenarios. Let’s assume some simple input and output scenarios Now we have to find the distances between nodes 4 and 13. int key1=13, key2=4; res = solve(root, min(key1, key2), max(key1, key2)); output = 6 The shortest distance is 6, which is through 4->6->3->8->10->14->13(the arrows show a path definition and not anything else). Let’s find another distance from two different nodes in the above ... Read More

C++ program to Replace a Node with Depth in a Binary Tree

Prateek Jangid
Updated on 10-Aug-2022 11:58:31

264 Views

Suppose we have a binary tree and we want to replace the depth of each node with its value. The depth of the node starts from 0 at the root node and increases by 1 for each level we go; for example, we have a binary tree like this; Here we replace, Node Value Depth 1 0 2 1 3 1 4 2 5 2 6 2 7 2 8 3 9 3 We do a simple ... Read More

Advertisements