Program for Markov matrix in C++

Sunidhi Bansal
Updated on 23-Sep-2019 08:18:42

330 Views

Given a matrix M[r][c] with ‘r’ number of rows and ‘c’ number of columns, we have to check that the given matrix is Markov matrix or not. If the input matrix is Markov matrix then print the output “It is a Markov matrix” and “it’s not an Markov matrix” if it is not a Markov matrix.Markov MatrixNow, what is Markov Matrix? A matrix M is a Markov matrix if and only if its sum of each row is equal to only 1.Like in the given example below −$$\begin{bmatrix}0.2 & 0.3 & 0.5 \0.1 & 0.7 & 0.2 \0.4 & 0.5 ... Read More

Program for Identity Matrix in C

Sunidhi Bansal
Updated on 23-Sep-2019 08:05:23

1K+ Views

Given a square matrix M[r][c] where ‘r’ is some number of rows and ‘c’ are columns such that r = c, we have to check that ‘M’ is identity matrix or not.Identity MatrixIdentity matrix is also known as Unit matrix of size nxn square matrix where diagonal elements will only have integer value one and non diagonal elements will only have integer value as 0Like in the given Example below −$$I1=\begin{bmatrix}1 \end{bmatrix}, \ I2=\begin{bmatrix}1 & 0 \0 & 1 \end{bmatrix}, \ I3=\begin{bmatrix}1 &0 & 0 \0 &1 & 0 \0 &0 &1 \end{bmatrix}, \In=\begin{bmatrix}1 &0 &0  &...&0 \0 &1 &0 ... Read More

Program to check if matrix is upper triangular in C++

Sunidhi Bansal
Updated on 23-Sep-2019 07:39:19

645 Views

Given a square matrix M[r][c] where ‘r’ is some number of rows and ‘c’ are columns such that r = c, we have to check that ‘M’ is upper triangular matrix or not.Upper Triangular MatrixUpper triangular matrix is a matrix in which the elements above the main diagonal(including the main diagonal) are not zero and below elements are zero only.Like in the given Example below −In above figure the red highlighted elements are lower elements from the main diagonal which are zero and rest elements are non-zero.ExampleInput: m[3][3] = { {1, 2, 3},    {0, 5, 6},    {0, 0, ... Read More

Program to check if matrix is lower triangular in C++

Sunidhi Bansal
Updated on 23-Sep-2019 07:32:35

446 Views

Given a square matrix M[r][c] where ‘r’ is some number of rows and ‘c’ are columns such that r = c, we have to check that ‘M’ is lower triangular matrix or not.Lower Triangular Matrix −Lower triangular matrix is a matrix in which the elements below the main diagonal(including the main diagonal) are not zero and above elements are zero only.Like in the given Example below −In above figure the red highlighted elements are upper elements from the main diagonal which are zero and rest elements are non-zero.ExampleInput: m[3][3] = { {1, 0, 0},    {2, 3, 0},    {4, ... Read More

Program to check Involutory Matrix in C++

Sunidhi Bansal
Updated on 23-Sep-2019 07:25:46

93 Views

Given a matrix M[r][c], ‘r’ denotes number of rows and ‘c’ denotes number of columns such that r = c forming a square matrix. We have to check whether the given square matrix is an Involutory matrix or not.Involutory MatrixA matrix is called Involutory matrix if and only if, when a matrix gets multiplied with itself and its result is an identity matrix. A matrix I is Identity matrix if and only if its main diagonal is one and other elements than the main diagonal are zero. So, we can say a matrix is Involutory matrix if and only if ... Read More

Program to check idempotent matrix in C++

Sunidhi Bansal
Updated on 23-Sep-2019 07:17:38

218 Views

Given a matrix M[r][c], ‘r’ denotes number of rows and ‘c’ denotes number of columns such that r = c forming a square matrix. We have to check whether the given square matrix is an Idempotent matrix or not.Idempotent MatrixA matrix ‘M’ is called Idempotent matrix if and only the matrix ‘M’ multiplied by itself returns the same matrix ‘M’ i.e. M * M = M.Like in the given example below −We can say that the above matrix is multiplied by itself and returns the same matrix; hence the matrix is Idempotent matrix. ExampleInput: m[3][3] = { {2, -2, -4},   ... Read More

Program to check diagonal matrix and scalar matrix in C++

Sunidhi Bansal
Updated on 23-Sep-2019 07:07:15

427 Views

Given a matrix M[r][c], ‘r’ denotes number of rows and ‘c’ denotes number of columns such that r = c forming a square matrix. We have to find whether the given square matrix is diagonal and scalar matrix or not, if it is diagonal and scalar matrix then print yes in the result.Diagonal matrixA square matrix m[][] will be diagonal matrix if and only if the elements of the except the main diagonal are zero.Like in the given figure below −Here, the elements in the red are main diagonal which are non-zero rest elements except the main diagonal are zero making it a Diagonal ... Read More

Program to Convert Centimeter to Feet and Inches in C

Sunidhi Bansal
Updated on 23-Sep-2019 06:49:00

1K+ Views

Given with the length into centimeter as an input, the task is to convert the given length into feet and inchesWe can use length conversion formula for this −1 feet = 30.48 cm 1 inche = 2.54 cmExampleInput-: centimetre = 100 Output -: Length in meter = 3m    Length in Kilometer = 0.003kmAlgorithmStart Step 1 -> Declare function to perform conversion    double convert(int centimeter)       set double inch = 0.3937 * centimetre       set double feet = 0.0328 * centimetre       print inch and feet Step 2 -> In main()    Declare ... Read More

Program to convert centimeter into meter and kilometre in C++

Sunidhi Bansal
Updated on 23-Sep-2019 06:44:35

323 Views

Given with the length into centimeter as an input, the task is to convert the given length into meter and kilometreWe can use length conversion formula for this −1 m = 100 cm 1 km = 100000 cmExampleInput-: centimetre = 100 Output -: Length in meter = 3m    Length in Kilometer = 0.003kmAlgroithmStart Step 1 -> Declare variables as centimetre, meter, kilometre Step 2 -> set centimetre=100 Step 3 -> Set meter = centimeter / 100.0 Step 4 -> Set kilometer = centimeter / 100000.0 Step 5 -> print meter and kilometer StopExample#include using namespace std; int main(){    float centimeter, meter, kilometer;    centimeter = 300;    // Converting centimeter into meter and kilometer    meter = centimeter / 100.0;    kilometer = centimeter / 100000.0;    cout

Program to check if a given year is leap year in C

Sunidhi Bansal
Updated on 23-Sep-2019 06:41:09

449 Views

Leap year has 366 days whereas a normal year has 365 days and the task is to check through the program whether the given year is a leap year or not.The logic for it can be through checking if year is divided by 400 or 4 but if the number is not divided by either of the number than it will be a normal year.ExampleInput-: year=2000 Output-: 2000 is a Leap Year Input-: year=101 Output-: 101 is not a Leap yearAlgorithmStart Step 1 -> declare function bool to check if year if a leap year or not bool check(int ... Read More

Advertisements