C++ Articles

Page 54 of 597

Count of obtuse angles in a circle with 'k' equidistant points between 2 given points in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 252 Views

We are given a circle with K equidistant points on its circumference. Also we are given two points A and B. The goal is to count the number of triangles possible using these points such that they have an obtuse angle ACB( angle greater than 90o) inside them. The points A and B are such that A < B.Here K=8, A=2, B=5, count of points=2 (C, C’) such that angle LACB, LAC’B are obtuse.Let us understand with examplesInput − k=10, A=2, B=4Output − Count of obtuse angles in a circle with ‘k' equidistant points between 2 given points are − ...

Read More

Equal Sum and XOR in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 936 Views

In this problem, we are given an integer n. Our task is to create a program to find the count of integers from i = 0 to n, where sum is equal to XOR i.e. (n+i) = (n^i).Let’s take an example to understand the problem, Input:  n = 4Output: 4Explanation: Considering all values of i from 0 to n, i = 0,  4 + 0 = 4, 4^0 = 4i = 1,  4 + 1 = 5, 4^1 = 5i = 2,  4 + 2 = 6, 4^2 = 6i = 3,  4 + 3 = 7, 4^3 = 7i = 4, ...

Read More

Count of occurrences of a "1(0+)1" pattern in a string in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 264 Views

We are given a string str containing 0s, 1s and other alphabets . It also contains patterns of the form “1(0+)1” where 0+ means any number (>0) of consecutive 0s. The goal is to find such patterns ( “1(0+)1” ) inside string str.Let us understand with examplesInput − str = “abb010bb10111011”Output − Count of occurrences of a “1(0+)1” pattern in a string are − 2Explanation − The patterns inside str are highlighted: “abb010bb10111011”, “abb010bb10111011”Input − str = “01001011001001100”Output − Count of occurrences of a “1(0+)1” pattern in a string are − 4Explanation − The patterns inside str are highlighted: “01001011001001100”, ...

Read More

Equalize an array using array elements only in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 505 Views

In this problem, we are given an array of n elements. Our task is to create a program to count the number of operations to equalize an array using elements only.We need to count the number of adding or subtraction operations that will be performed to make all the elements of the array equal.Let’s take an example to understand the problem, Input: arr[] = {4, 0, 3, 1, 2}Output: 3Explanation: The equal value will be 2.The overall sum will be the same. We will be taking 1 from value at arr[3] and then adding it to value at arr[1].Then we will take 2 ...

Read More

Count of pairs of (i, j) such that ((n % i) % j) % n is maximized in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 200 Views

We are given a number num as input. The goal is to find the number of pairs of form (i, j) such that ((num%i)%j)%num is maximized and i and j both are in range [1, num].Let us understand with examplesInput − num=4Output − Count of pairs of (i, j) such that ((n % i) % j) % n is maximized are − 3Explanation − Pairs will be: (3, 2), (3, 3), (3, 4)Input − num=6Output − Count of pairs of (i, j) such that ((n % i) % j) % n is maximized are − 4Explanation − Pairs will be: ...

Read More

Equilibrium index of an array in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 694 Views

In this problem, we are given an array arr[] consisting of n integer values. Our task is to create a program to find the equilibrium index of an array.Equilibrium Index is the index at which the sum of all elements before the index is the same as the sum of all elements after the index.For array arr[] of size n, the equilibrium index is e such that, sum (arr[0… e-1] ) = sum (arr[e… n-1])Let’s take an example to understand the problem, Input: arr[] = {5, 1, 2, 8, 3, 4, 1}Output: 3Explanation: arr[0] +  arr[1] + arr[2] = arr[4] + arr[5] + arr[6]=> ...

Read More

Count of strings where adjacent characters are of difference one in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

We are given a num number as input. The goal is to count the number of possible strings of length num such that all adjacent characters have difference between ascii values as 1.If num is 2 then strings will be “ab”, “ba”, “bc”, “cb”, ……..”yz”, “zy”.Let us understand with examplesInput − num=3Output − Count of strings where adjacent characters are of difference one are − 98Explanation − Some sample strings are: “abc”, “aba”, “cde” …..”xyx”, “zyz”, “xyz”.Input − num=2Output − Count of strings where adjacent characters are of difference one are − 50Explanation − Some sample strings are: “ab”, “ba”, ...

Read More

Euler Method for solving differential equation in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 5K+ Views

In this problem, we are given a differential equation f(x, y) = dy/dx with initial value y(x0) = y0. Our task is to find the solution of the equation using the Euler method for solving differential equations.EULER METHODEuler method also known as forward euler Method is a first order numerical procedure to find the solution of the given differential equation using the given initial value.For a differential equation f(x, y) = dy / dx. Euler method is defined as, y(n+1) = y(n) + h * f( x(n), y(n) )The value h is step size which is calculated as, h = (x(n) - x(0)) ...

Read More

Count of distinct rectangles inscribed in an equilateral triangle in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 278 Views

We are an equilateral triangle with side length. The goal is to count the number of distinct rectangles that can be present inside the triangle such that horizontal sides of the rectangle are parallel to the base. Also all end points of the rectangle touch the dots as shown.Let us understand with examplesInput − sides=3Output − Count of distinct rectangles inscribed in an equilateral triangle are − 1Explanation − The figure above shows the rectangle.Input − sides=10Output − Count of distinct rectangles inscribed in an equilateral triangle are − 200Approach used in the below program is as followsAs from the ...

Read More

Eulerian Number in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 634 Views

In mathematics, the Eulerian number is a special type of combination number. It defines the number of permutations in which the next element is a specific number greater than the previous one.Denoted as,  A(n, m) is permutation from 1 to n in which two numbers vary by m.Problem Statement: In this problem, we are given two numbers m and n. And we need to find the number of permutations that are the Eulerian Number.Let’s take an example to understand the problem, Input:  n = 4, m = 2Output: 11Explanation: All permutations of number from 1 to 4 are −1 2 3 4       ...

Read More
Showing 531–540 of 5,962 articles
« Prev 1 52 53 54 55 56 597 Next »
Advertisements