Check Idempotent Matrix in C++

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

383 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

Check Diagonal and Scalar Matrix in C++

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

635 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

Convert Centimeter to Feet and Inches in C

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

2K+ 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

Convert Centimeter to Meter and Kilometre in C++

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

507 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

Check If a Given Year is a Leap Year in C

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

671 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

Calculate Value of NCR in C++

Sunidhi Bansal
Updated on 23-Sep-2019 06:37:22

3K+ Views

Given with n C r, where C represents combination, n represents total numbers and r represents selection from the set, the task is to calculate the value of nCr.Combination is the selection of data from the given in a without the concern of arrangement. Permutation and combination differs in the sense that permutation is the process of arranging whereas combination is the process of selection of elements from the given set.Formula for permutation is -:nPr = (n!)/(r!*(n-r)!)ExampleInput-: n=12 r=4 Output-: value of 12c4 is :495AlgorithmStart Step 1 -> Declare function for calculating factorial    int cal_n(int n)    int temp ... Read More

Calculate the Value of NPR in C Program

Sunidhi Bansal
Updated on 23-Sep-2019 06:32:26

501 Views

Given with the n P r, where P represents Permutation, n represents total numbers and r represents arrangement the task is to calculate the value of nPr.Permutation is the arrangement of data in a sequence or order. Permutation and combination differs in the sense that permutation is the process of arranging whereas combination is the process of selection of elements from the given set.Formula for permutation is −nPr = (n!)/(n-r)!ExampleInput-: n=5 r=2 Output-: 20AlgorithmStart Step 1 -> declare function to calculate value of nPr    int cal_n(int n)       IF n Declare function to calculate the final ... Read More

Calculate the Perimeter of a Decagon in C

Sunidhi Bansal
Updated on 20-Sep-2019 14:44:39

189 Views

What is Decagon?Given with side, the task is to calculate the perimeter of decagon. Decagon is a type of polygon with 10-sides that’s why it is also known as 10-gon polygon. It have 10 vertices and edges. A regular decagon has sides of equal length and each internal angle of degree 144.Given below is the figure of DecagonTo calculate the volume and surface area of Frustum of cone there is a formulaPerimeter = 10 * SideExampleInput-: side=10 Output-: perimeter of Decagon is : 100 Input -: side = 20 Output -: perimeter of Decagon is : 200AlgorithmStart Step 1 ... Read More

Calculate Volume of Pyramid in C++

Sunidhi Bansal
Updated on 20-Sep-2019 14:30:34

1K+ Views

Given with sides depending upon the type of base of pyramid the task is to calculate the volume of pyramid.Pyramid is a 3-D figure whose outer surfaces are triangular meeting at the common point forming the sharp edge of pyramid. Volume of pyramid depends upon the type of base it will have.There are different types of base a pyramid can be made up of, like −Triangular −It means pyramid will have triangular base, than the volume of pyramid will beFormula - : (1/6) * a * b * hSquare −It means pyramid will have square base, than the volume of ... Read More

Calculate Volume of Ellipsoid in C++

Sunidhi Bansal
Updated on 20-Sep-2019 14:25:59

280 Views

Given with r1, r2 and r3 the task is to find the volume of ellipsoid. An ellipsoid is a quadric surface, a surface that may be defined as the zero set of a polynomial of degree two in three variables. Among quadric surfaces, an ellipsoid is characterized by either of the two following properties.Formula used to calculate volume of ellipsoidVolume of Ellipsoid : (4/3) * pi * r1 * r2 * r3ExampleInput-: r1 = 6.3, r2 = 43.4, r3 = 3.7 Output-: volume of ellipsoid is : 4224.87AlgorithmStart Step 1 -> define macro as    #define pi 3.14 Step 2 ... Read More

Advertisements