Server Side Programming Articles - Page 2331 of 2650

C Program to sum the digits of a given number in single statement

Ravi Ranjan
Updated on 15-Apr-2025 15:27:34

592 Views

The calculation of the sum of the digits of a number in a single statement means that only one line of code will be doing the addition operation. The addition operation should not extend more than one statement. In this article, we have a number and our task is to calculate the sum of the digits of the number in a single statement in c. Here is a list of approaches: Using for Loop Using Recursive Function Using for Loop This approach uses a for loop to calculate the ... Read More

C++ Program to Implement the linear congruential generator for Pseudo Random Number Generation

Ravi Ranjan
Updated on 08-May-2025 18:49:19

1K+ Views

The Linear Congruential Generator (LCG) is a very simple technique to generate a sequence of numbers that looks like random numbers but is actually determined. It is one of the reasons to call it a pseudo-random number. The Linear Congruential Generator (LCG) technique generates a random number based on the previous number and uses a linear recurrence to generate the sequence of random numbers. In this article, we have set an initial value of Xn and defined the value of the constants. Our task is to generate pseudo-random numbers using the linear congruential generator in C++. Formula of Linear ... Read More

C Program to print numbers from 1 to N without using semicolon

Ravi Ranjan
Updated on 15-Apr-2025 15:27:59

2K+ Views

Printing numbers from 1 to N is an easy task that can be achieved using loops, but to print numbers from one to N without using a semicolon is a tricky question. We will discuss two different methods to solve this question using iteration and recursion approaches. In this article, our task is to print numbers from 1 to 'n' and we don't have to use a semicolon. The approaches are listed below: Using Iteration Using Recursion Using Iteration This approach uses the iterative approach, where we have used the while loop to print the numbers from 1 to N. The num

C++ Program to Check Whether a Directed Graph Contains a Eulerian Cycle

Ravi Ranjan
Updated on 28-May-2025 12:12:00

657 Views

The Euler path is a path by which we visit every edge exactly once. We can use the same vertices for multiple times. The Euler Circuit is a special type of Euler path. When the starting vertex of the Euler path is also connected with the ending vertex of that path, then it is called the Euler Cycle. In this article, our task is to check if the Eulerian cycle exists in the given directed graph or not. In the above figure, there is a directed graph and its respective adjacency matrix. The Eulerian path respective to the ... Read More

C++ Program to Check Whether a Graph is Strongly Connected or Not

Ravi Ranjan
Updated on 29-May-2025 19:19:15

435 Views

To check if a graph is strongly connected or not, we need to check if for any pair of vertices u and v in the directed graph, there exists a directed path from u to v and a directed path from v to u. In this article, we have a directed graph with five vertices and its respective adjacency matrix. Our task is to check if the given graph is strongly connected or not. Example of Strongly Connected Graph The graph displayed in the figure below is an example of a strongly connected graph. In the above graph, ... Read More

C++ Program to Check the Connectivity of Directed Graph Using DFS

Ravi Ranjan
Updated on 30-May-2025 18:59:12

797 Views

To check if a directed graph is connected or not, we need to check if there exists a path between every pair of vertices. A directed graph (or digraph) is a graph where each edge has a direction, edges are in ordered pairs, and edges traverse from the source vertex (the tail) to the destination vertex (the head). In this article, we have a directed graph with five vertices and its respective adjacency matrix. Our task is to use Depth-first Search(DFS) to check the connectivity of the given graph. Example of Connected Graph In the figure given below, we have ... Read More

C++ Program to Implement Interpolation Search Algorithm

Ravi Ranjan
Updated on 21-Apr-2025 14:40:31

1K+ Views

The interpolation search is an improved version of the binary search. The list is divided using the mid element in the binary search whereas the interpolation search algorithm tries to locate the exact position using the interpolation formula. For this algorithm to work properly, the data collection should be in a sorted form and equally distributed. In this article, we have a sorted array. Our task is to implement the interpolation search algorithm algorithm on this sorted array in C++. The formula used in this algorithm to find the position is given below: Interpolation Position Search Formula pos = ... Read More

C++ Program to Implement Counting Sort

Ravi Ranjan
Updated on 08-May-2025 18:48:44

4K+ Views

Counting sort is a stable and non-comparison-based sorting technique, that is used to sort the objects according to the keys that are small integers. It counts the number of keys whose key values are same. It works by counting the occurrences of elements in the array. This sorting technique is efficient when difference between different keys are not so big, otherwise it can increase the space complexity. In this article, we have an unsorted array. Our task is to implement the counting sort algorithm to sort the given unsorted array in C++. Example Here is an example of ... Read More

C++ Program to Implement Shell Sort

Ravi Ranjan
Updated on 07-May-2025 18:37:21

2K+ Views

The shell sorting technique is based on the insertion sort. In the insertion sort, sometimes we need to shift a large block to insert an item in the correct position. In shell sort, we avoid large number of shifting. The sorting is done with specific interval. After each pass, the interval is reduced to make smaller interval. We call also say we use gapped insertion sort in shell sort as we compare elements separated by a gap. In this article, we have an unsorted array. Our task is to sort the given unsorted array by implementing the shell sort in ... Read More

C++ Program to Implement Insertion Sort

Ravi Ranjan
Updated on 15-Apr-2025 19:19:13

19K+ Views

The insertion sort technique is an in-place comparison-based sorting algorithm used to sort the numbers in an ascending or descending order. It is similar to the card sorting technique. In this technique, we pick up one element from the data set and shift the data elements to make a place to insert the picked-up element into the data set. In this article, we have an array of integers. Our task is to implement insertion sort in C++ to sort the given array. Example Here is an example of an array before sorting and after sorting using insertion sort: ... Read More

Advertisements