Programming Articles - Page 2401 of 3363

A matrix probability question in C?

sudhir sharma
Updated on 04-Oct-2019 07:02:49

212 Views

The matrix probability question Calculates the probability that whether an element will be inside the given matrix after taking N steps and any direction. This means we need to find what is the probability of an element not going out of the scope of the matrix even after moving N positions in any direction.In this problem, we are free to move the matrix element in all four directions (left, right, up, down). And the probability of moving elements is same 0.25 or 1/4.The program will return 0 if the element steps out otherwise not.Example Live Demo#include int isSafe(int x, int ... Read More

_Generic keyword in C ? 1: 20

sudhir sharma
Updated on 04-Oct-2019 06:59:01

879 Views

_Generic keyword in C is used to define MACRO for different data types. This new keyword was added to the C programming language in C11 standard release. the _Generic keyword is used to help the programmer use the MACRO in a more efficient way.this keyword translate the MACRO based on the type of the variable. let's take an example ,#define dec(x) _Generic((x), long double : decl, \ default : Inc , \ float: incf )(x)The above syntax is how to declare any MACRO as generic for different methods.Let's take an example code, this code will define a MACRO that will ... Read More

New ways to Assign values to Variables in C++ 17 ?

sudhir sharma
Updated on 04-Oct-2019 06:56:08

510 Views

In C++ 17, there are introduced two new ways by which a programmer can assign values to a variable or declared them. In this update, elser then the classical way of assigning values to a variable the following two ways to initialise values.Classical methodInitially the assignment operator ‘=’ is used for assignment and declaration of a variable. assignment of a variable using = looks like, datatype variable_name = value;Example, int val = 243;New methodUniform initialisationIn uniform initialisation of variables we do not use the ‘=’ operator. the value is enclosed inside a pair of curly braces ' {} '. Value ... Read More

Adapter Pattern in C++?

sudhir sharma
Updated on 04-Oct-2019 06:51:58

329 Views

An adapter pattern is used to convert the interface of a class into an interface that is expected by the client. An adapter helps the programmer to make its classes work together and make sure the user requirement is fulfilled by making incompatible interfaces completable.let's understand a bit more about the adapter pattern. The concept of adapter is taken from the real world. as in the real world We use adapters to connect things that are incompatible with each other. let's take an example, in modern day smartphones the 3.5 mm jack for earphones is missing, so the brands have ... Read More

Angular Sweep Algorithm in C++

sudhir sharma
Updated on 04-Oct-2019 06:48:06

617 Views

The algorithm to find the maximum number of points that can be enclosed in a circle of a given radius. This means that for a circle of radius r and a given set of 2-D points, we need to find the maximum number of points that are enclosed (lying inside the circle not on its edges) by the circle.For, this is the most effective method is the angular sweep algorithm.AlgorithmThere are nC2 points given in the problem, we need to find the distance between each of these points.Take an arbitrary point and get the maximum number of points lying in ... Read More

C++ set for user defined data type?

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

563 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

162 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

How to serialize a map using the flexjson library in Java?

Aishwarya Naglot
Updated on 13-May-2025 15:54:20

416 Views

Serializing a Map in Java is the process of converting a Map object into a format that can be easily stored or transmitted, such as JSON or XML. We will use the Flexjson library to serialize a map in Java. We can serialize a Map using the serialize() method of the JSONSerializer class, which performs a shallow serialization of the target instance. Example of Serializing a Map We will take a map and see the output after serialization. Map map = new HashMap(); map.put("name", "Ansh"); map.put("age", "23"); map.put("city", "Mumbai"); map.put("country", "India"); After serialization, the map will look like this: {"name":"Ansh", ... Read More

Area of squares formed by joining midpoints repeatedly in C?

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

145 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

398 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

Advertisements