Found 7332 Articles for C++

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

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

3K+ 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

133 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

7K+ 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

3K+ 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

Sum of a Geometric Progression in C++

AYUSH MISHRA
Updated on 11-Dec-2024 09:50:54

3K+ Views

What is Geometric Progression? A geometric progression is a sequence of numbers where each term is obtained by multiplying the previous term by a fixed number. This fixed number is known as the common ratio and it should be a non-zero. In this article, we are going to learn how we can find the sum of given n terms in geometric progression in C++. We are given first-term, common ratio, and number of terms for which we have to find the sum of geometric progression. Formula for Calculating Sum of Geometric Progression Sn= a (1 - rn)/(1 - r)  ... Read More

Pythagorean Triplet in an Array Using C++

AYUSH MISHRA
Updated on 09-Dec-2024 13:18:10

4K+ Views

Pythagorean Triples Pythagorean triples are a set of three distinct numbers a, b, and c which satisfy the condition: a2 + b2 = c2 These numbers a, b, and c are known as Pythagorean triples. We can say that these three numbers represent the sides of a right-angled triangle. These three sides are known as triplets of the array. Problem Description We are given an array of integers, and we have to find if there exist three distinct numbers in the array which form the Pythagorean triplet in C++. Below are examples to demonstrate the problem statement clearly: ... Read More

Advertisements