Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 37 of 44

C++ program to find the probability of a state at a given time in a Markov chain

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 567 Views

In this article, we will be discussing a program to find the probability of reaching from the initial state to the final state in a given time period in Markov chain.Markov chain is a random process that consists of various states and the associated probabilities of going from one state to another. It takes unit time to move from one state to another.Markov chain can be represented by a directed graph. To solve the problem, we can make a matrix out of the given Markov chain. In that matrix, element at position (a, b) will represent the probability of going ...

Read More

C++ program to find whether only two parallel lines contain all coordinates points or not

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 454 Views

In this article, we will be discussing a program to find whether only two parallel lines can hold all the given coordinates points.For this we will be given an array, such that the coordinates will be (i, arr[i]). Let us suppose we are given an array, arr = {2, 6, 8, 12, 14}Then we can have these points on two parallel lines, the first line containing (1, 2), (3, 8) and (5, 14). The second line having the rest coordinates i.e (2, 6) and (4, 12).This problem can be solved by comparing the slopes of the lines made by the ...

Read More

C++ program to find whether there is a path between two cells in matrix

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 250 Views

In this article, we will be discussing a program to find whether there exists a path between two cells in a given matrix.Let us suppose we have been given a square matrix with possible values 0, 1, 2 and 3. Here, 0 means Blank Wall1 means Source2 means Destination3 means Blank CellThere can only be one Source and Destination in the matrix. The program is to see if there’s a possible path from Source to Destination in the given matrix moving in all four possible directions but not diagonally.Example#include using namespace std; //creating a possible graph from given array class ...

Read More

C++ program to find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 163 Views

In this article, we will be discussing a program to find ΔX which is added to the numerator and denominator both of given fraction (a/b) to convert it to another given irreducible fraction (c/d).For example, let us suppose we have been given with the following values, a = 4 | b = 2 | c = 4 | d = 3then ΔX would be 4 such that (a + ΔX)/(b + ΔX) = 8/6 = 2/3As we know, (a + ΔX)/(b + ΔX) = c/d. Solving this equation for ΔX, we getΔX = (bc - ad) / (d - c)Example#include ...

Read More

How to sort a Vector in descending order using STL in C++?

Ayush Gupta
Ayush Gupta
Updated on 21-Feb-2025 818 Views

The problem is to sort a vector in descending order using C++'s Standard Template Library(STL). Sorting in descending order means rearranging the elements of the vector so that the largest elements come first, followed by smaller elements, all the way down to the smallest element at the end of the vector. Let's say we have the following vector of integers: vector v = {4, 2, 9, 1, 7}; We want to sort this vector so that the elements are arranged in descending order: v = {9, 7, 4, 2, 1}; In this article, we will show you how ...

Read More

File Handling through C++ Classes

Ayush Gupta
Ayush Gupta
Updated on 11-Dec-2024 1K+ Views

In this tutorial, we will be discussing a program to understand File Handling through C++ classes. What's File Handling? File handling is an important concept in programming, which allows a program to read from and write to files. C++ has built-in classes and functions for file handling, which is done using file stream classes that are part of the  library. The most common file stream classes in C++ are ofstream, ifstream, fstream. ofstream: This class is used for output file streams, where it allows the user to write data to files. ...

Read More

Type Inference in C++ (auto and decltype)

Ayush Gupta
Ayush Gupta
Updated on 03-Dec-2024 339 Views

In this tutorial, we will be discussing a program to understand Type interference in C++ (auto and decltype). In the case of auto keyword, the type of the variable is defined from the type of its initializer. Further, with decltype, it lets you extract the type of variable from the called element. auto type Example Here is the following example of auto-type in C++. #include using namespace std; int main() { auto x = 4; auto y = 3.37; auto ptr = & x; cout

Read More

Program to find N-th term of series 0, 2,1, 3, 1, 5, 2, 7, 3...in C++

Ayush Gupta
Ayush Gupta
Updated on 03-Oct-2020 226 Views

In this problem, we are given a number N. Our task is to create a Program to find N-th term of series 0, 2, 1, 3, 1, 5, 2, 7, 3...in C++.Problem Description − We are given the Series −0, 2, 1, 3, 1, 5, 2, 7, 3...N TermTo find the Nth term of this series, we will formula the general term of the series and then find the Nth term.Let’s take an example to understand the problem, Input − N = 7Output − 2Solution Approach :To solve the problem and find the general formula for the series. We need ...

Read More

Program to find N-th term of series 0, 9, 22, 39, 60, 85, 114, 147, ...in C++

Ayush Gupta
Ayush Gupta
Updated on 03-Oct-2020 206 Views

In this problem, we are given a number N. Our task is to create a Program to find N-th term of series 0, 9, 22, 39, 60, 85, 114, 147, …in C++.Problem Description − We are given the Series −0, 9, 22, 39, 60, 85, 114, 147, ....NtermsTo find the Nth term of this series, we will formula the general term of the series and then find the Nth term.Let’s take an example to understand the problem, Input − N = 6Output − 85Solution Approach:To find the general term of the series. Let’s observe the growth of the values of ...

Read More

Program to find N-th term of series 1, 3, 12, 60, 360...in C++

Ayush Gupta
Ayush Gupta
Updated on 03-Oct-2020 222 Views

In this problem, we are given a number N. Our task is to create a Program to find N-th term of series 1, 3, 12, 60, 360...in C++.Given Series1, 3, 12, 60, 360, 2520 … N TermsLet’s take an example to understand the problem, Input − N = 6Output − 2520Solution Approach:The general term formula for this one is a bit tricky. So, the increase in the series values is huge. So, there can be a few possibilities factorial or exponentials. So, we will first consider factorial, and on observing we can see the growth half as half of the ...

Read More
Showing 361–370 of 433 articles
« Prev 1 35 36 37 38 39 44 Next »
Advertisements