Found 7197 Articles for C++

Check if a Binary String contains A pairs of 0s and B independent 0s or not

Aishwarya Mani Tripathi
Updated on 08-Sep-2023 12:28:21

158 Views

Checking if a Binary String contains A pairs of 0s and B independent 0s or not is a common problem encountered in computer science, particularly in the field of algorithms and data structures. The problem statement is quite simple and plays a significant role in various fields, such as cryptography, network security, and machine learning. In this tutorial, we will discuss a solution to this problem using C++. We will first provide an overview of the approach starting with defining the problem statement with some examples and, then we will dive into the implementation details. So let’s get started! ... Read More

Time Required to Meet in Equilateral Triangle

Vanshika Sood
Updated on 08-Sep-2023 11:42:35

170 Views

An equilateral triangle is a triangle with all of its sides equal in length. As the three sides are equal, the three angles opposing the equal sides are also equal in magnitude. As a result, it is also known as an equiangular triangle, with each angle measuring 60 degrees. The centroid of an equilateral triangle is the point where its three medians intersect. In an equilateral triangle, all three sides are of equal length and all three angles are of equal measure, so each median will intersect at the same point, which is the centroid. Problem Statement Given length ... Read More

Program to calculate Volume and Surface area of Hemisphere

Vanshika Sood
Updated on 08-Sep-2023 11:34:47

413 Views

A sphere is a three-dimensional geometric shape that is perfectly round like a ball, while a hemisphere is one half of a sphere. In essence, a sphere would split into two hemispheres if it were sliced in half. Hemispheres are identified by their curving surface, which radiates out from the sphere's core. The Greek terms "hemi" (half) and "sphaira" (sphere) are where the name "hemisphere" comes from. Hemispheres are used to describe and simulate a variety of events in a number of disciplines, including geography, astronomy, mathematics, and physics. Volume of a Hemisphere The volume of a hemisphere is equal ... Read More

Numbers whose Factorials end with n Zeros

Vanshika Sood
Updated on 08-Sep-2023 11:46:46

517 Views

A factorial of a number is the product of all positive integers up to the given number. For example, the factorial of 5 is denoted as 5! and is equal to the product of all positive integers up to 5: 5! = 5 x 4 x 3 x 2 x 1 = 120 The number of zeros at the end of the decimal representation of a number's factorial is referred to as the "trailing zeros" in a factorial. The factorial of 5, for instance, is 120, which has one trailing zero, while the factorial of 10, on the other hand, ... Read More

Leibniz Harmonic Triangle

Vanshika Sood
Updated on 08-Sep-2023 11:19:04

332 Views

The Leibniz harmonic triangle, also known as Leibniz's series or the Leibniz formula, is a triangular arrangement of numbers discovered by German mathematician and philosopher Gottfried Wilhelm Leibniz in the late 17th century. The Leibniz harmonic triangle is a triangular arrangement of fractions. We start at the top with the number and the outermost terms are reciprocal of the natural numbers depicting that particular row number. In general, a term in the leibniz harmonic triangle can be determined by the following equation, where r is the row number and c is the column number with the condition that c

First Occurrence of a Digit in a Given Fraction

Vanshika Sood
Updated on 08-Sep-2023 11:11:02

196 Views

The decimal expansion of a fraction is the decimal representation of the fraction's value. In the following article we discuss two approaches to find the first occurrence of c in a/b. Problem Statement Given three integers a, b, c, locate the first instance of c in the fraction a/b after the decimal point. Print-1 if it does not exist. Sample Examples Input a = 5, b = 6, c = 3 Output 2 Explanation $$\mathrm{\frac{a}{b}=\frac{5}{6}=0.83333}$$ So c=3 occurs at the 2nd place after the decimal point. Hence the output is 2. Input a = -10, b = ... Read More

Minimize the Absolute Difference of Sum of Two Subsets

Vanshika Sood
Updated on 08-Sep-2023 11:06:08

639 Views

To Minimize the Absolute Difference of Sum of Two Subsets, we partition a vector into two subsets i.e. we divide the elements of the vector into two smaller vectors such that each element of the original vector belongs to one of the two smaller vectors, and the two smaller vectors are disjoint. For example, if we have a vector v = {1, 2, 3, 4, 5}, then one possible partitioning of v into two subsets is S1 = {1, 3, 4} and S2 = {2, 5}, where each element of v belongs to either S1 or S2, and the ... Read More

Sum of an array using pthreads

Divya Sahni
Updated on 28-Sep-2023 15:20:41

1K+ Views

Pthreads is an execution model that helps use multiple processors to work at the same time for solving a problem. It is independent of the programming language. Problem Statement Given an array of integers. Find the sum of all the elements of the array using pthreads. Need for Multithreading for Calculating sum The problem is to add the elements in an array. Although it is a simple problem where a linear traversal of the array can do the work very easily with a time complexity of O(n) where n is the number of elements in the array. But if we ... Read More

Print numbers in the range 1 to n having bits in an alternate pattern

Divya Sahni
Updated on 28-Sep-2023 14:26:29

179 Views

Alternate bit pattern implies the positioning of 0’s and 1’s in a number at an alternate position i.e. no two 0s or 1’s are together. For example, 10 in binary representation is (1010)2 which has an alternate bit pattern as 0’s and 1’s are separated by each other. Problem Statement Given an integer, N. Find all the integers in the range 1 to N where the bit pattern of the integer is alternating. Example 1 Input: 10 Output: 1, 2, 5, 10 Explanation $\mathrm{(1)_{10} = (1)_2, (2)_{10} = (10)_2, (5)_{10} = (101)_2, (10)_{10} = (1010)_2}$ Example 2 Input: ... Read More

Jacobsthal and Jacobsthal-Lucas Numbers

Divya Sahni
Updated on 28-Sep-2023 14:19:17

385 Views

Jacobsthal Numbers Lucas sequence 𝑈𝑛(𝑃, 𝑄) where P = 1 and Q = -2 are called Jacobsthal numbers. The recurrence relation for Jacobsthal numbers is, $$\mathrm{𝐽_𝑛 = 0\: 𝑓𝑜𝑟 \: 𝑛 = 0}$$ $$\mathrm{𝐽_𝑛 = 1\: 𝑓𝑜𝑟 \: 𝑛 = 1}$$ $$\mathrm{𝐽_𝑛 = 𝐽_𝑛−1 + 2𝐽_{𝑛−2}\: 𝑓𝑜𝑟 \: 𝑛 > 1}$$ Following are the Jacobsthal numbers − 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365, …. Jacobsthal-Lucas Numbers Complementary Lucas sequence $\mathrm{𝑉_𝑛(𝑃, 𝑄)}$ where P = 1 and Q = -2 are called JacobsthalLucas numbers. The recurrence relation for Jacobsthal-Lucas numbers is, $\mathrm{𝐽_𝑛}$ = ... Read More

Advertisements