Found 7192 Articles for C++

Sum of a Geometric Progression in C++

AYUSH MISHRA
Updated on 11-Dec-2024 12:38:32

0 Views

Problem DescriptionA 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.The formula for calculating the sum of the Geometric Progression is:Sn= a (1 - rn)/(1 - r) where Sn is ... Read More

Sum of a Geometric Progression in C++

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

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

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

Parallelogram Star Pattern using C++

AYUSH MISHRA
Updated on 28-Nov-2024 11:14:45

10K+ Views

When we start learning to code, practicing star patterns is one of the best ways to improve logic building. One of the engaging patterns is the parallelogram pattern. In this article, we are going to learn how to print a Parallelogram Star Pattern using C++. What is Parallelogram Pattern? A parallelogram pattern is a geometrical arrangement of stars in a parallelogram shape. The stars are printed in such a manner that if we draw a closed figure on the boundary of the printed pattern, it will resemble a parallelogram. Each row is shifted with space, which creates a diagonal ... Read More

C++ Program to Return Quadrants in which a given Coordinates Lies

AYUSH MISHRA
Updated on 28-Nov-2024 11:31:47

7K+ Views

Cartesian-coordinate System and Quadrants The cartesian-coordinate system is divided into four Quadrants: Quadrant I, Quadrant II, Quadrant III, and Quadrant IV. In this article, we are going to learn how we can determine the quadrant in which given points i.e., x and y, lie. Problem Description We are given the position of a point (x, y), and we have to determine in which quadrant this point lies. Example Input: (-3, 2) Output: Quadrant II Input: (2, 5) Output: Quadrant I Input: (2, -4) Output: Quadrant IV Input: (-6, -3) Output: Quadrant III Using Conditional Quadrant Identification Approach ... Read More

C++ Program to check if a Number is Harshad Number

AYUSH MISHRA
Updated on 22-Nov-2024 08:56:51

0 Views

What is Harshad Number?A Harshad number is a special type of number. A Harshad number or Niven number is a number that is completely divisible by the sum of its digits without leaving any remainder. In this article, we are going to learn how we can check whether a given number is a Harshad number or not. Problem Description  We are given a number and we have to return true if the given number is Harshad or Niven number and return false if the given number is not Harshad number. Examples of Input and OutputInput 108 Output yes Explanation The sum of digits: 1 + 0 + 8 ... Read More

C++ Program for Sum of Infinite Terms in GP

AYUSH MISHRA
Updated on 21-Nov-2024 19:28:56

9K+ Views

What is Geometric Progression (GP)? Geometric Progression (GP) is a sequence of numbers where each term is generated by multiplying the previous term by a constant value. This constant value in GP is known as the common ratio. In this article, we are going to discuss how to calculate the sum of infinite terms in a GP using different approaches in C++. Note: The important condition to remember is that a positive valid sum of infinite GP is only possible if the absolute of the common value (r) is less than 1, i.e., ∣r∣ < 1. Methods to Calculate ... Read More

C++ program to return all Boundary Elements of a Matrix

AYUSH MISHRA
Updated on 28-Nov-2024 11:49:26

7K+ Views

boundary elements of a matrix The boundary elements of a matrix are those elements that lie along its edges. A matrix is a two-dimensional array that can be of any given size. The boundary elements are those present on the edges of the matrix. Problem Description We are given a matrix of size m × n. We need to find the boundary elements of the matrix. Boundary elements are the elements present on the top and bottom rows and the first and last columns of the matrix. Below are examples to understand the boundary traversal of a matrix: ... Read More

C++ Program to check if a Number is Harshad Number

AYUSH MISHRA
Updated on 21-Nov-2024 11:40:18

6K+ Views

A Harshad number is a special type of number. A Harshad number or Niven number is a number that is completely divisible by the sum of its digits without leaving any remainder. In this article, we are going to learn how we can check whether a given number is a Harshad number or not. Problem Description We are given a number and we have to return true if the given number is Harshad or Niven number and false if the given number is not a Harshad number. Example 1 Input: 108 Output: yes Explanation: The sum ... Read More

C++ program to print all non-boundary elements of matrix

AYUSH MISHRA
Updated on 20-Nov-2024 23:05:54

6K+ Views

A matrix is a two-dimensional array. The elements that are present on the edges are called boundary elements, and the elements that are present inside the matrix, not present on the edges, are known as non-boundary elements. In this article, we are going to discuss how to print non-boundary elements of the matrix. Problem Description We are given a matrix and we have to print all non-boundary elements present in the matrix. Rows and columns are present ... Read More

Previous 1 ... 3 4 5 6 7 ... 720 Next
Advertisements