Found 7192 Articles for C++

C++ program to calculate potential energy if mass and height are given

AYUSH MISHRA
Updated on 20-Jan-2025 19:10:49

7K+ Views

What is Potential Energy? Potential energy is a type of stored energy stored by an object due to its position relative to other objects. It is an important concept in physics and is commonly calculated when studying objects in gravitational fields. In this tutorial, we are going to learn how to calculate the potential energy of an object in C++ if the mass and height are given. Formula for Calculating Potential Energy The formula for potential energy is as follows: Potential Energy = m × g × h Where:m is the mass of the object (in kilograms).g is the gravitational ... Read More

C++ Program to Print Hollow Square Pattern

AYUSH MISHRA
Updated on 23-Jan-2025 23:11:31

20K+ Views

When we start learning to code, practicing star patterns is one of the best ways to improve logic building. One of the simplest yet fascinating patterns is the hollow square pattern. In this article, we are going to learn how to print a Hollow Square Pattern using C++. What is Hollow Square Pattern? A hollow square pattern is a geometrical arrangement of stars forming a square shape, but the stars are present only at the boundary of the square. The stars are printed in such a manner that the edges of the square are filled with stars, while the interior ... Read More

Finding sum of alternative elements of the array using C++

AYUSH MISHRA
Updated on 17-Jan-2025 19:38:41

7K+ Views

The sum of alternate elements has various real-life applications such as signal processing, data compression, pattern recognition, gaming, and financial data analysis. Problem Description In this article, we are going to learn how to find the sum of alternate elements of an array in C++. Alternate elements are present at even or odd indices of the array, depending on how we define them.  Example 1 Inputarray = [1, 2, 3, 4, 5] OutputSum_even = 9Sum_odd = 6 Explanation The alternate elements at the even index are 1, 3, 5 (at ... Read More

Setting up Sublime Text for C++ Competitive Programming Environment

guru
Updated on 20-Jan-2025 13:05:02

304 Views

The Sublime Text is a popular code editor due to its simplicity, speed and extensibility. While it may not have built-in C++ support, it's very easy to set up Sublime Text for competitive programming in C++. This guide will walk you through configuring Sublime Text to provide a smooth and efficient environment for C++ competitive programming. Steps to Set Up Sublime Text for C++ Competitive Programming 1. Install Sublime TextFirst, we need to install Sublime Text if you haven't already. Go to the Sublime Text website. Download and install the ... Read More

C++ Program to Calculate the Distance Between Two Points

AYUSH MISHRA
Updated on 06-Jan-2025 19:10:45

4K+ Views

Problem Description In this problem, we are given coordinate points of a 2-dimensional plane and a 3-dimensional plane, and we have to find the distance between these two points. In this article, we are going to discuss how we can find the distance between two points in C++. Approaches to Calculate Distance Between Two Points To solve this problem, here are the two approaches that can you use: Using 2D Coordinates Using 3D Coordinates Using 2D Coordinates In this approach, we use the direct distance formula to calculate ... Read More

Find the duplicate in an array of N+1 integers using C++

AYUSH MISHRA
Updated on 06-Jan-2025 19:34:38

4K+ Views

Problem Description In this problem, we are given an array that contains all unique elements except one element which is present exactly two times in the array. We have to return that element which is present two times in the array. In this article, we are going to learn how we can find duplicates in an array of N+1 integers in C++. Example Input: array = {1, 3, 4, 2, 2} Output: 2 Explanation: 2 is the only element in the array that occurs two times. Approaches to Find Duplicate Element in an Array ... Read More

Calculating the Area of a Triangle Using Heron’s Formula in C++

AYUSH MISHRA
Updated on 31-Dec-2024 21:57:01

3K+ Views

Problem Description We are given the three sides of a triangle, and we have to calculate the area of the triangle using Heron's formula. In this article, we are going to discuss how we can calculate the area of a triangle using Heron's Formula in C++. Heron's Formula The formula for calculating the semi-perimeter of the triangle is: s = (a + b + c) / 2 Then, apply Heron's formula to calculate the area of the triangle. Heron's formula for calculating the area of the triangle is: Area = √ s * (s - a) * (s - ... Read More

Check If a Number Is Greater Than Zero in C++

AYUSH MISHRA
Updated on 07-Jan-2025 18:52:04

4K+ Views

Problem Description In this problem, we are given a number and have to check whether this number is greater than zero. Using the if-else and ternary approach to check if the given number is greater than zero, equal to zero, or less than zero. In this article, we will discuss how we can find if a given number is greater than zero or not in C++. Prerequisite If-else operator: This operator allows the program to execute certain code blocks based on whether a condition is true or false. Syntax of If-else operator if (condition) { // ... Read More

C++ Program to Subtract Two Numbers

AYUSH MISHRA
Updated on 30-Dec-2024 19:22:43

16K+ Views

Problem Description In this problem, we are given two numbers and we have to find the value obtained after subtracting one number from another. In this article, we are going to learn how we can subtract two numbers in C++ using different approaches. Example 1 Input number1 = 8number2 = 12 Output 4 Explanation The subtraction of number2 - number1 i.e. 12 - 8 will result in 4. Example 2 ... Read More

How to Insert Multiple Elements at Given Positions in a Vector?

AYUSH MISHRA
Updated on 24-Dec-2024 13:22:09

6K+ Views

What is a Vector in C++?A vector is a dynamic array as the size of the vector changes during the program's execution. If we insert more elements in the vector it expands its size and if we remove elements from the vector it shrinks in size. A vector is part of the Standard Template Library (STL). Problem DescriptionIn this problem, we are given a vector and have to insert an element at a certain position. In this article, we are going to learn how to insert multiple positions in a vector in C++ using different approaches. Below are some examples to ... Read More

Advertisements