Server Side Programming Articles - Page 2162 of 2650

C++ set for user defined data type?

Akansha Kumari
Updated on 29-May-2025 18:57:55

535 Views

A set is a data structure that is used to store distinct values (meaning no two elements can have the same value) in ascending or descending order. Set for User-defined Data TypesWe can directly use sets for built-in data types, but for user-defined data types, values cannot be directly stored, because a set compares the elements to maintain order, but for user-defined data types such as array or struct, the compiler will not be able to perform a comparison between them. The set container is defined under the header file. So to use user-defined datatypes into a stack, we ... Read More

The basic_string c_str function in C++ STL?

sudhir sharma
Updated on 04-Oct-2019 06:39:11

144 Views

The basic_string c_str function that returns a pointer to an array of characters that is terminated using null character. It is an inbuilt method that has the value of a string that has null character termination.Syntax to define a c_str function in C++ −const Char ptr* c_str() constAbout the functionIt is an inbuilt method for the c++ STL library. No parameters can be passed to the method. It returns a char pointer. This pointer points to NULL terminated character array.Example Live Demo#include #include using namespace std; int main() {    string s = "I Love Tutorials Point";    int ... Read More

Area of squares formed by joining midpoints repeatedly in C?

sudhir sharma
Updated on 03-Oct-2019 13:24:05

133 Views

Area of a square is equal to the product of sides of the square.We are considering a figure in which the midpoints of sides of each square make another square. And so on until a specific number of squares.This figure shows a square made by joining the midpoints of a square.For this figure the let the side be a, The length of side of inner square will beL2 = (a/2)2 + (a/2)2 L2 = a2(1/4 + 1/4) = a2(1/2) = a2/2 L = a2/ (\sqrt{2}).Area of square2 = L2 = a2/2.For the next square, the area of square 3 = ... Read More

Absolute distinct count in a sorted array in C++?

Akansha Kumari
Updated on 22-Jul-2025 15:53:47

377 Views

An array is a data structure that is used to store elements of the same data type, where a sorted array, in which the elements are arranged in ascending or descending order. The absolute distinct count gives the count of absolute (non-negative or unsigned) values of distinct (unique) elements present in an array. In this article, we will learn how to find the count of absolute values of all distinct elements in the given sorted array in C++. Consider the following input and output scenarios to under the problem better: Scenario 1 Input: [-5, -2, 1, 2, 5, 5, 6, ... Read More

Area of the biggest possible rhombus that can be inscribed in a rectangle in C?

sudhir sharma
Updated on 03-Oct-2019 13:13:52

278 Views

A rhombus inscribed in a rectangle touches the sides of the rectangle so by this we can infer that the diagonals of the largest inscribed rhombus are equal to the length and breadth of the rectangle.If we have the length(l) and breadth(b) of the rectangle, the length of the diagonal of the largest rhombus inscribed inside it is d1 = l and d2 = b.The area of a rhombus is given by the formula, Area = (d1*d2)/2Putting the values of d1 and d2. We get, Area = (l*b)/2Using this formula we can create a program that calculates the area of ... Read More

Area of a circle inscribed in a rectangle which is inscribed in a semicircle in C?

sudhir sharma
Updated on 03-Oct-2019 13:10:41

2K+ Views

A circle inscribed in a rectangle touches the larger side of the rectangle with its ends i.e. the length is tangent to the circle.A rectangle inscribed in a semicircle touches its arc at two points. The breadth of the rectangle is equal to the diameter of the circle.If R is the radius of semi-circle.Length of the rectangle = √2R/2Breadth of the rectangle = R/√2Radius of biggest circle inscribed isr = b/2 = R/2√2Using this formula we can find the area of this circle inscribed in a rectangle which is inscribed in a semicircle, Area = (π*r2) = π*R/8Example Live Demo#include ... Read More

Anti Clockwise spiral traversal of a binary tree in C++?

sudhir sharma
Updated on 03-Oct-2019 13:02:36

183 Views

Anti-Clockwise spiral traversal of a binary tree is traversing the elements of a tree in such a way that if traversed they make a spiral but in reverse order. The following figure shows how a anti-clockwise spiral traversal of binary tree.The Algorithm defined for spiral traversal of a binary tree works in the following way −Two variables i and j are initialized and values are equated as i = 0 and j = height of variable. A flag is used to check while section is to be printed. Flag is initially is set of false. A loop working till i ... Read More

Absolute Difference of even and odd indexed elements in an Array in C++?

sudhir sharma
Updated on 01-Aug-2025 16:58:01

992 Views

An array in C++ is a collection of elements of the same data type stored in contiguous memory locations. Arrays provide a way to store multiple values using a single variable name, and each element can be accessed using an index starting from 0. Even and Odd Indexed Elements in an Array Each element in an array has an index. Indexes that are divisible by 2 (like 0, 2, 4, etc.) are known as even indexes, while indexes that are not divisible by 2 (like 1, 3, 5, etc.) are referred to as odd indexes. For example, in the ... Read More

A Product Array Puzzle in C?

sudhir sharma
Updated on 03-Oct-2019 12:51:23

349 Views

An array is a container of elements of the same data types. In product array Puzzle, the product of all elements is found.In this Product Array Puzzle, we need to find the product of all elements of the array except element. The condition is that you cannot use the division operator and store this to another array.For solving this we will be creating two products, one for all left elements and one for all right elements. And then adding this left and right products to get the desired products.Example Live Demo#include #include void productfind(int arr[], int n) {    int *left ... Read More

Adding one to number represented as array of digits in C++?

Nishu Kumari
Updated on 29-Jul-2025 14:22:35

329 Views

In this problem, we are given a number in the form of an array, and each digit of the number is stored at one index of the array, and the most significant digit comes first. Our task is to add 1 to this number and return the updated number in the same array format. Let's understand it with some example scenarios. Scenario 1 Input: Input_arr[] = {2, 6, 1} Output: 262 Explanation: The array represents 261. Adding 1 gives 261 + 1 = 262. Scenario 2 Input: input_arr[] = {5, 9, 9, 9} Output: 6000 Explanation: The array ... Read More

Advertisements