Programming Articles

Page 42 of 2544

How to Check Whether a Number is a Triangular Number or Not in Java?

Vivek Verma
Vivek Verma
Updated on 13-Jun-2025 4K+ Views

A Triangular number of a natural number n, which is defined as the sum of all natural numbers starting from 1 to n. It is called triangular as we can represent it in the form of an equilateral triangular grid by using the total number of points where the row number equals the point number, which means in the 1st row 1 point, in the 2nd row 2 points, in the 3rd row 3 points, and so on. Examples of triangular numbers are 1, 3, 6, 10, 21, 55, etc. In simple terms, we can say a number is a ...

Read More

How To Check Whether a Number is an Empire Number or Not in Java?

Vivek Verma
Vivek Verma
Updated on 13-Jun-2025 596 Views

What is Empire Number? A number is said to be an Empire number if it is a prime number, and when we reverse that number, we should get another prime number. For example, let's consider the number 17. We know that 17 is a prime number, and if we reverse this number, we get 71, which is also a prime number. Therefore, 17 is known as an empire number. Here are some other examples of prime numbers such as 11, 13, 17, etc. Input & Output Scenarios Below are a few input and output scenarios that help to understand the ...

Read More

How To Check if a Given Point Lies Inside a Rectangle in Java?

Vivek Verma
Vivek Verma
Updated on 13-Jun-2025 3K+ Views

A Rectangle is a closed two-dimensional shape that has 4 sides and 4 corners. The opposite sides are of the same length and parallel to each other. All 4 interior angles are equal, angles measure 90 degrees. It is a four-sided polygon. Following is the diagram of the Rectangle: Checking Points Inside Rectangle A point is said to lie inside a rectangle if its x and y coordinates are between the x and y coordinates of the opposite corners of the rectangle. To determine whether the point lies within the rectangle, we will use the following approaches: ...

Read More

Print leading zeros with C++ output operator

Aman Kumar
Aman Kumar
Updated on 12-Jun-2025 7K+ Views

Here we will see how to print leading zeros as output in C++. We know that if we directly put some zeros before some numeric values, then all zeros are discarded, and only exact numbers are printed.Printing Leading Zeros with C++ Output Operator We can manipulate the output sequence in C++ by utilizing the iomanip header. In this header, we have two manipulators, setw() and setfill(). The setw() function is used to create space between the previous text and the current text, and then we use setfill(char) to add characters to that field. Example of Printing Leading Zeros In this ...

Read More

How to get the parent process of the Process API in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 12-Jun-2025 954 Views

In this article, we will learn to get the parent process of the Process API in Java 9. First, we will know about Process API and its methods, after that we will learn about the ProcessHandle interface. Process API In Java, the Process API, we can perform any operation regarding a process. The Process class provides methods for performing input on the processes, performing output to the processes, finding child and parent processes of the currently running process, and destroying the process. The following are some of the common methods of the Process API: destroy(): ...

Read More

C++ Program to print the diamond shape

Farhan Muhamed
Farhan Muhamed
Updated on 12-Jun-2025 749 Views

In this article, we will learn how to print a diamond shape with 2n rows and n columns for a given size n using C++. For example, if n = 4, the diamond shape will look like this: Algorithm to Print Diamond Shape To print the diamond shape, we can follow these steps: Take an integer input n from the user. To print upper half of the diamond, use a loop that runs from i = 1 to i

Read More

C++ Program to Check if any Graph is Possible to be Constructed for a Given Degree Sequence

Farhan Muhamed
Farhan Muhamed
Updated on 12-Jun-2025 228 Views

We are given an array of integers containing the degree of each vertex in a graph. Our task is to check if it is possible to construct a graph with the given degree sequence. Example: int degrees[] = {3, 2, 2, 0} Output: Not Possible Explanation: The first vertex has degree 3, which means it must be connected to three other vertices. But the last vertex has degree 0, meaning it cannot be connected to any other vertex. Hence, it is impossible to construct a graph with this degree sequence. To implement this in C++, we can ...

Read More

Minimum removals to make array sum even in C++

Ravi Ranjan
Ravi Ranjan
Updated on 12-Jun-2025 310 Views

In this article, we have an array arr[] of N integers. Our task is to write a program to find the minimum number of elements needed to be removed from the given array so that the sum of the remaining elements is even. Example The following example demonstrates the minimum number of elements we need to remove from the array for the sum to be even: Input: arr = {12, 23, 40, 53, 17} Output: 1 Input: arr = {20, 11, 13, 40, 24} Output: 0 The explanation of ...

Read More

Minimum removals to make array sum odd in C++

Ravi Ranjan
Ravi Ranjan
Updated on 12-Jun-2025 326 Views

In this article, we have an array arr[] of N integers. Our task is to write a program to find the minimum number of elements needed to be removed from the given array so that the sum of the remaining elements is odd. Example The following example demonstrates the minimum number of elements we need to remove from the array for the sum to be odd: Input: arr = {12, 23, 40, 53, 17} Output: 0 Input: arr = {20, 11, 13, 40, 24} Output: 1 The explanation of the above example is ...

Read More

Count elements smaller than or equal to x in a sorted matrix in C++

Ravi Ranjan
Ravi Ranjan
Updated on 12-Jun-2025 329 Views

In this article, we are given a matrix of size m x n and an integer variable X. The row elements and the first column of the matrix are sorted in increasing order. Our task is to count the number of elements that are equal to or less than the given X value. Counting Elements Smaller Than X in a Sorted MatrixHere are the approaches for counting elements smaller than X in a sorted matrix: Using Linear Search Using Staircase Search Using Linear ...

Read More
Showing 411–420 of 25,433 articles
« Prev 1 40 41 42 43 44 2544 Next »
Advertisements