Found 7346 Articles for C++

Nicomachus’ Theorem

Eva Sharma
Updated on 24-Aug-2023 18:17:20

168 Views

According to Nicomachus’ Theorem, the sum of the cubes of the first n integers is equal to the square of the nth triangular number. Or, we can also say − The sum of cubes of first n natural numbers is equal to square of sum of first natural numbers. Putting it algebraically, $$\mathrm{\displaystyle\sum\limits_{i=0}^n i^3=\lgroup \frac{n^2+n}{2}\rgroup^2}$$ Theorem $$1^3 = 1$$ $$2^3 = 3 + 5$$ $$3^3 = 7 + 9 + 11$$ $$4^3 = 13 + 15 + 17 + 19\vdots$$ Generalizing $$n^3 =\lgroup n^2−n+1\rgroup+\lgroup n^2−n+3\rgroup+⋯+\lgroup n^2+n−1\rgroup$$ Proof By Induction For all n Ε Natural ... Read More

Equal sum array partition excluding a given element

Eva Sharma
Updated on 24-Aug-2023 18:00:27

87 Views

Problem Statement For an index and an arr[]. Check if the array[] can be partitioned into two disjoint sets, excluding arr[index] such that the sum of both sets has equal value. Example 1 Input arr[] = {4, 3, 1, 2}, Index = 1 Output No Explanation We have to exclude arr[1] = 3 All possible sets are − Set 1: (4), Set 2: (2, 1), sum = 4≠3 Set 1: (4, 1), Set 2: (2), sum = 5≠2 Set 1: (4, 2), Set 2: (1), sum = 6≠1 No combination satisfies the conditions. Example 2Input arr[] ... Read More

Squared Triangular Number (Sum of Cubes)

Eva Sharma
Updated on 24-Aug-2023 17:58:22

59 Views

A square triangular number, also referred to as a triangular square number, is a number that is both a triangular number and a perfect square. Square triangular numbers have an unlimited number of possible values; the first few are − 0, 1, 36, 1225, 41616... A triangular number or triangle number counts objects arranged in an equilateral triangle. The nth triangular number is the number of dots in the triangular arrangement with n dots on each side and is equal to the sum of the n natural numbers from 1 to n. The sequence of triangular numbers, ... Read More

How are Java and C++ related?

Priya Mishra
Updated on 23-Aug-2023 12:54:52

80 Views

Introduction These days, Java and C++ are widely utilized in competitive programming. These two programming languages are utilized generally in industry and competitive programming due to their impressive characteristics. C++ is a commonly used programming language due to its efficiency, fast speed, and dynamic memory use. In terms of software development, Java is incomparable to any other programming language. Java is extensively utilized in the IT sector. Now we will look into how Java and C++ are similar. What is Java? Java is an Object-Oriented programming, general-purpose, and high-level language. It is mainly used for coding web applications. Java ... Read More

Swapping four Variables without a Temporary Variable

Simran Kumari
Updated on 23-Aug-2023 10:43:22

465 Views

By the title "Swapping four variables without a temporary variable, " What do you understand? Let's decode. Here the question is asking us to swap the values of four variables without creating any additional temporary variables. Using a temporary variable to hold one of the values temporarily in various programming languages makes shifting the values of two variables simple. The use of temporary variables, however, becomes ineffective and time−consuming when swapping the values of more than two variables. Explanation Suppose we have four variables a, b, c, and d with the following values: a = 5 (101) b = 9 ... Read More

Sum of Bitwise AND of all Possible Subsets of given Set

Simran Kumari
Updated on 23-Aug-2023 10:41:45

108 Views

What do you understand by the problem `Sum of bitwise AND of all possible subsets of given set`? Let’s decode. The problem is asking to find the sum of the bitwise AND of all possible subsets of a given set. Let’s try to understand the problem with an example. Suppose we have a set {1, 2, 3}. What are the possible subsets for this set? The possible subsets are {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, and {1, 2, 3}. Now lets calculate the bitwise AND for each subset. The bitwise AND of these subsets can be calculated ... Read More

Squares of Numbers with Repeated Single Digits

Simran Kumari
Updated on 23-Aug-2023 10:40:22

69 Views

What is the question `Square of numbers with repeated single digits` asking us to do? Let’s decode! The problem "Squares of numbers with repeated single digits" aims to find the square of numbers like 33, 44, 555, etc which contains repeated single digits. Approach 1: Naive Approach We can use the naive approach to calculate the square of numbers, which includes the following steps: Take the numbers as input Use the multiplication operator to calculate the square i.e square_of_number= number * number then print the result Implementation in C++ Here is the implementation of above approach Example #include ... Read More

Segregate Even and Odd Numbers

Simran Kumari
Updated on 23-Aug-2023 10:39:10

532 Views

What do you understand by the title `Segregate even and odd numbers` ? Let’s decode. The goal of this problem is to separate the even and odd numbers in the input array while preserving the order of the elements, which means that the even numbers should remain in the same relative order as they were in the input, and the odd numbers should remain in the same relative order as they were in the input. Suppose we have [3, 5, 2, 6, 8, 9, 10, 11] as input, then the output will be [2, 6, 8, 10, 3, 5, ... Read More

Reflection of a Point at 180-Degree Rotation of Another Point

Simran Kumari
Updated on 23-Aug-2023 10:37:13

129 Views

What do you understand by the heading `Reflection of a point at 180−degree rotation of another point`? Let’s decode it in this article. Let's assume we have two points (x1, y1) and (x2, y2) in a 2−D plane. Where (x2, y2) is the point of rotation and (x1, y1) is the point to be reflected. Now, suppose x1, y1 is rotated 180 degrees across x2, y2 , and we get x1`, y1`. Now, we can observe that, if we are given 2 points in a 2−d plane with one of the points rotating across the second point it ... Read More

Maximize a Value for a Semicircle of a given Radius

Simran Kumari
Updated on 24-Aug-2023 10:00:49

51 Views

What do understand by the question embedded in the title i.e Maximize a value for a semicircle of a given radius? The title `Maximize a value for a semicircle of a given radius` sounds unclear. Isn’t it? Let’s discuss what it means in the article below: According to the title, If we have a semicircle with radius R, we need to find the maximum value of the expression F = PS^2 + PQ, where P is a point on the circumference of the semicircle, and PQ and PS are the two segments connecting P to the two endpoints of ... Read More

Advertisements