Vector is a special type of array in C++, which have ability to resize itself automatically during insertion and deletion of elements.. In this article, we will learn how to use the vector container from the Standard Template Library (STL) in C++. What is a Vector? A vector is a container that stores data elements in a dynamic contiguous memory. It is similar to arrays but can change its size dynamically during execution. Meaning, we doesn't need explicitly mention the size of a vector, it will be calculated automatically by counting number of elements in it. Similar to arrays, ... Read More
Stack is a linear data structure that follows the Last In First Out (LIFO) principle. In this article, we will learn how to use the stack container from the Standard Template Library (STL) in C++. What is Stack? A stack is a container that stores data in a way that the last inserted data will be the first to be removed. This is same as a stack of plates, where the last plate placed on the top is the first one to be removed. The STL library of C++ provides a pre-defined stack data structure which comes with all ... Read More
A prime number is a number greater than 1 that has no divisors other than 1 and itself. For example, 2, 3, 5, 7, and 11 are prime numbers. In this article, we'll show you how to write a C++ program to display prime numbers between two intervals. ExampleFor example, given the interval from 0 to 50, we want to print all the prime numbers within this interval. Input: Starting interval: 0 Ending interval: 50 Output: Prime numbers in the interval [0, 50] are: 2 3 5 7 11 13 17 19 23 29 31 37 41 ... Read More
A prime number is a number greater than 1 that has no divisors other than 1 and itself. For example, 2, 3, 5, 7, and 11 are prime numbers. In this article, we'll show you how to write a C++ program to display prime numbers between two intervals using function. For example, given the interval from 0 to 50, we want to print all the prime numbers within this interval. Input: Starting interval: 0 Ending interval: 50 Output: Prime numbers in the interval [0, 50] are: 2 3 5 7 11 13 17 19 23 29 31 ... Read More
Natural numbers are positive numbers starting from 1, such as 1, 2, 3, and so on. Here, we will take a positive number n as input and and then will find the sum of all natural numbers from 1 up to n using recursion using C++ program. Example Input: n = 5 The sum of the first 5 natural numbers is: 1 + 2 + 3 + 4 + 5 = 15 Output: 15 Input: n = 8 The sum of the first 8 natural numbers is: 1 + 2 + 3 + 4 + 5 + 6 ... Read More
Any object, such as a dictionary, can be the return value of a Python function. To do so, create the dictionary object in the function body, assign it to any variable, and return the dictionary to the function's caller. Data values are stored as key-value pairs in dictionaries. A Python dictionary is a collection that is ordered, changeable, and forbids duplicates. In this article, we will discuss various methods to return a dictionary from a Python function. Using Dictionary Comprehension One line of Python code can create and initialize dictionaries using the simple and memory-efficient way known as Dictionary Comprehension. ... Read More
Serialization is the process that converts an object into a format that can be stored or transmitted easily. Excluding a Field in Gson During Serialization We might have some scenarios where we are asked or required to exclude a certain field from the object while serializing it. For example, we have a Student object with fields like name, age, and address. We want to serialize the object but exclude the address field for building basic information about the student in this case, we use In this article, we will learn how to exclude a field in Gson during serialization ... Read More
What are JSON and JsonNode? JSON is a format that is used to store data and exchange data between a server and a client. To know more about JSON, you can refer to the JSON Tutorial. A JsonNode is Jackson's tree model for JSON. To read JSON into a JsonNode with Jackson by creating an ObjectMapper instance and call the readValue() method. We can access a field, array or nested object using the get() method of the JsonNode class. We can return a valid string representation using the asText() method and ... Read More
Calculating a power means multiplying the base by itself as many times as the exponent indicates. In this article, we'll show you how to write a C++ program to calculate the power of a number using recursion. For example, 2 raised to the power of 3 (2^3) means multiplying 2 by itself 3 times: 2 * 2 * 2, which gives 8. Using Recursion to Calculate Power To calculate the power of a number, we use recursion, where a function keeps calling itself with smaller values until it reaches a stopping point. Here are the steps we ... Read More
An array stores multiple values of the same data type. To find the average, we add all the numbers and then divide the total by how many numbers there are. In this article, we'll show you how to write a C++ program to calculate the average of numbers using an array. For example, if we have the numbers 40, 80, 10, 75, and 25, their total is 230, and the average is 230 / 5 = 46. Approaches for Calculating Average Using Arrays In C++, we can calculate the average of numbers in an array in two main ... Read More