Ravi Ranjan

Ravi Ranjan

About

Hello readers, I am a technical content engineer having expertise in front-end web development and C++.

117 Articles Published

Articles by Ravi Ranjan

Page 11 of 12

C++ Program to Implement Fermat’s Little Theorem

Ravi Ranjan
Ravi Ranjan
Updated on 23-Apr-2025 1K+ Views

Fermat's Little Theorem states that if p is a prime number and a is an integer not divisible by p, then a^(p-1) is congruent to 1 modulo p. It can be represented as a(p-1) ≡ 1 (mod p). It can also be said that if any integer a is raised to the (p-1) where p is a prime and gcd(a, p) =1, then a^(p-1)-1 is divisible by p. In this article, we have two integers i.e. 'a' and a prime number 'p' such that a is not divisible by p. Our task is to implement Fermat's Little theorem using these ...

Read More

C++ Program to Implement Park-Miller Random Number Generation Algorithm

Ravi Ranjan
Ravi Ranjan
Updated on 23-Apr-2025 701 Views

The Park-Miller algorithm is a type of linear congruential generator (LCG) that is used to generate pseudo-random numbers. It is also called the minimal standard random number generator. The general formula of a random number generator (RNG) of this type is: X_{k+1} = g X(k) mod n where the modulus n is a prime number or a power of a prime number, the multiplier g is an element of high multiplicative order modulo n, and the seed X0 is co-prime to n. In this article, we will be using Park-Miller algorithm to generate 5 pseudo-random numbers using C++. Here is ...

Read More

C++ Program to Implement Russian Peasant Multiplication

Ravi Ranjan
Ravi Ranjan
Updated on 22-Apr-2025 626 Views

The Russian Peasant multiplication is used to multiply two numbers without using the multiplication operator. It involves constant use of halving and doubling the numbers. In this article, we have two integers, our task is to find the product of these two integers by implementing russian peasant multiplication in C++. Steps to Implement Russian Peasant Multiplication We will follow these simple steps to find the product using Russian Peasant multiplication: We have created a function russianPeasant() that accepts both the numbers (n and m) as arguments. Then we used a ...

Read More

C++ Program to Generate Random Numbers Using Probability Distribution Function

Ravi Ranjan
Ravi Ranjan
Updated on 22-Apr-2025 2K+ Views

The probability density function (pdf) is a function that describes the relative likelihood for this random variable to take on a given value. It is also called as density of a continuous random variable. The probability of the random variable fall within a particular range of values is given by the integral of this variable's density over that range, So, it is given by the area under the density function but above the horizontal axis and between the lowest and greatest values of the range. Probability Distribution is based upon this probability density function. In this article, we will generate ...

Read More

C++ Program to Generate Random Numbers Using Middle Square Method

Ravi Ranjan
Ravi Ranjan
Updated on 22-Apr-2025 2K+ Views

The middle-square method is one of the simplest methods of generating random numbers. This method will either begin repeatedly generating the same number or cycle to a previous number in the sequence and loop indefinitely. For a generator of n-digit random numbers, the period can be no longer than the specified n(number of digits). If the middle n digits are all zeroes, the generator then generates zeroes forever. In this article, we will implement a C++ program to generate ten 4-digits random number using the middle-square method. Steps for Middle-Square Random Number Generation The steps for generating random numbers ...

Read More

C++ Program to Find kth Largest Element in a Sequence

Ravi Ranjan
Ravi Ranjan
Updated on 18-Apr-2025 622 Views

In this article, we have an unsorted array. Our task is to find the kth maximum element of that array using C++. Here is an example to understand the meaning of k. If k =2, you can say the second highest value, for k =3, the third highest value. The approaches that we will be using are mentioned below: Using Sorting Using Max Heap Using Min Heap Using Quick Select Using Binary Search Tree Using ...

Read More

C++ Program to Implement Selection Sort

Ravi Ranjan
Ravi Ranjan
Updated on 17-Apr-2025 22K+ Views

The selection sort is an in-place comparison-based simple sorting algorithm. In the selection sort technique, the list is divided into two parts: sorted and unsorted. The minimum element from the unsorted part is selected and swapped with the element at the beginning of the list. Similarly, the next minimum value from the unsorted list is placed at the next position in the sorted list, and this keeps repeating until the whole array is sorted. In this article, we have an unsorted array. Our task is to sort this array using selection sort in C++. Here is an example of selection ...

Read More

largest string formed by choosing words from a given Sentence as per given Pattern

Ravi Ranjan
Ravi Ranjan
Updated on 16-Apr-2025 394 Views

To find the largest string formed by choosing words from a given sentence, a user should know about the lexicographically largest string. A lexicographically largest string is a string, when sorted alphabetically, it would appear at the last if we form all possible strings from the selected words. For example: {lion, zebra, apple} will be lexicographically sorted as {apple, lion, zebra}. In this article, we have been given a string and a pattern. Based on this pattern, we have to find the lexicographically largest string matching the given pattern by choosing words from the sentence using C. Here is an ...

Read More

Why is the size of an empty class not zero in C++?

Ravi Ranjan
Ravi Ranjan
Updated on 15-Apr-2025 2K+ Views

The size of an empty class is not zero in C++ as it allocates one unique address to the object in the memory. The size can not be 0, because the two classes can not have the same memory address. So, the size of an empty class is 1 byte which does not hold any data, it is just for memory allocation. In this article, we will see an example of checking the size of an object of an empty class in C++. Demonstrating Size of an Empty Class In this approach, we have two C++ classes. One class ...

Read More

C++ Program to Find Minimum Element in an Array using Linear Search

Ravi Ranjan
Ravi Ranjan
Updated on 15-Apr-2025 1K+ Views

Linear search is a sequential searching algorithm where we traverse every element within the input array and compare it with the key element to be found. The minimum element refers to the smallest element in the array. In this article, we have an array of integers. Our task is to find the minimum element in that array using linear search. Here are the three approaches you can use to find the minimum element: Using Value Using Index Using Pointer Using Value In this approach, ...

Read More
Showing 101–110 of 117 articles
« Prev 1 8 9 10 11 12 Next »
Advertisements